HTML esoterica - en-GB vs en_GB
HTML enthusiasts have long puzzled over a curious difference between the lang attribute used in the <meta> element and its underscore-separated format. The lang attribute specifies the primary language for an element's contents and attributes containing text. Its value must adhere to the BCP 47 standard, which allows only the characters A-Z, a-z, 0-9, and hyphen-minus (%x2D).
For example, "en" represents English, "en-GB" signifies British English, and "en-CA" denotes Canadian English. Each part of the language tag is separated by a hyphen.
However, there are alternative ways language tags can appear in HTML. When sharing a web page on platforms like social media or messaging apps, Open Graph Protocol (OGP) can be utilized to display a preview of the page. The locale used in these tags follows the format language_TERRITORY, with the default being en_US, indicating English (United States).
This locale signifies the language and territory of the tags, not the page itself. So, a page could be written in Japanese but have OGP tags in Cherokee. Similarly, a site's name could be in French, while the description is in English.
The question arises: why does the lang attribute use a hyphen while the meta element employs an underscore? The Open Graph Protocol defines several data types, including date, boolean, string, enum, and currency. While the date is always presented in ISO8601 format, regardless of locale, booleans, strings, enums, and currency could potentially benefit from a locale-based representation.
Currency, in particular, relies on the user's locale to determine the appropriate thousand separator and decimal mark. For instance, "5,99" or "10.000,32" could be used based on the page's intended audience.
Facebook, the developer of Open Graph Protocol, maintains a discussion forum plagued with spam and a seemingly abandoned GitHub repository. Despite this, a relevant pull request references an obsolete page that offers an explanation. The pull request clarifies that a locale comprises the language, territory, and code set combination that identifies a set of language conventions, including collation, case conversion, character classification, message catalogs, date-and-time representation, monetary symbols, and numeric representation.
These conventions are essential for understanding user preferences and displaying content appropriately. Thus, a locale proves more useful than a plain language, especially when displaying numbers in different formats.
Rewritten by urgent.news; may contain errors — check the original.
Source: htmhell.dev
Read the original at htmhell.dev →
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up