ietf language tag

an ietf bcp 47 language tag is a standardized code or tag that is used to identify human languages in the internet (a language code). the tag structure has been standardized by the internet engineering task force (ietf) in "best current practice (bcp) 47"; the subtags are maintained by the "iana language subtag registry". 
to distinguish language variants for countries, regions, or writing systems (scripts), ietf language tags combine subtags from other standards such as iso 639, iso 15924, iso 3166-1 and un m.49.
for example, the tag "en" stands for english; "es-419" for latin american spanish; "rm-sursilv" for romansh sursilvan; "sr-cyrl" for serbian written in cyrillic script; "nan-hant-tw" for min nan chinese using traditional han characters, as spoken in taiwan; and "gsw-u-sd-chzh" for zürich german. in its accordance with iso 639-3, however, it does not provide codes for distinguishing between arabic-based scripts, and maintains two duplicate codes for punjabi, as well as a number of dubious or non-existent language distinctions made by its parents standard.
it is used by computing standards such as http, html, xml and png.󠀁
history.
ietf language tags were first defined in rfc 1766, edited by harald tveit alvestrand, published in march 1995. the tags used iso 639 two-letter language codes and iso 3166 two-letter country codes, and allowed registration of whole tags that included variant or script subtags of three to eight letters.
in january 2001, this was updated by rfc 3066, which added the use of iso 639-2 three-letter codes, permitted subtags with digits, and adopted the concept of language ranges from http/1.1 to help with matching of language tags.
the next revision of the specification came in september 2006 with the publication of rfc 4646 (the main part of the specification), edited by addison philips and mark davis and rfc 4647 (which deals with matching behaviour). rfc 4646 introduced a more structured format for language tags, added the use of iso 15924 four-letter script codes and un m.49 three-digit geographical region codes, and replaced the old registry of tags with a new registry of subtags. the small number of previously defined tags that did not conform to the new structure were grandfathered in order to maintain compatibility with rfc 3066.
the current version of the specification, rfc 5646, was published in september 2009. the main purpose of this revision was to incorporate three-letter codes from iso 639-3 and 639-5 into the language subtag registry, in order to increase the interoperability between iso 639 and bcp 47.
syntax of language tags.
each language tag is composed of one or more "subtags" separated by hyphens (-). each subtag is composed of basic latin letters or digits only.
with the exceptions of private-use language tags beginning with an "x-" prefix and grandfathered language tags (including those starting with an "i-" prefix and those previously registered in the old language tag registry), subtags occur in the following order:
subtags are not case-sensitive, but the specification recommends using the same case as in the language subtag registry, where region subtags are uppercase, script subtags are title case, and all other subtags are lowercase. this capitalization follows the recommendations of the underlying iso standards.
optional script and region subtags are preferred to be omitted when they add no distinguishing information to a language tag. for example, "es" is preferred over "es-latn", as spanish is fully expected to be written in the latin script; "ja" is preferred over "ja-jp", as japanese "as used in japan" does not differ markedly from japanese as used elsewhere.
not all linguistic regions can be represented with a valid region subtag: the subnational regional dialects of a primary language are registered as variant subtags. for example, the "valencia" variant subtag for the valencian variant of the catalan is registered in the language subtag registry with the prefix "ca". as this dialect is spoken almost exclusively in spain, the region subtag "es" can normally be omitted.
furthermore, there are script tags that do not refer to traditional scripts such as latin, or even scripts at all, and these usually begin with a "z." for example, "zsye" refers to emojis, "zmth" to mathematical notation, "zxxx" to unwritten documents and "zyyy" to undetermined scripts.
ietf language tags have been used as locale identifiers in many applications. it may be necessary for these applications to establish their own strategy for defining, encoding and matching locales if the strategy described in rfc 4647 is not adequate.
the use, interpretation and matching of ietf language tags is currently defined in rfc 5646 and rfc 4647. the language subtag registry lists all currently valid public subtags. private-use subtags are not included in the registry as they are implementation-dependent and subject to private agreements between third parties using them. these private agreements are out of scope of bcp 47.
list of common primary language subtags.
the following is a list of some of the more commonly used primary language subtags. the list represents only a small subset (less than 2 percent) of primary language subtags; for full information, the language subtag registry should be consulted directly.
relation to other standards.
although some types of subtags are derived from iso or un core standards, they do not follow these standards absolutely, as this could lead to the meaning of language tags changing over time. in particular, a subtag derived from a code assigned by iso 639, iso 15924, iso 3166, or un m.49 remains a valid (though deprecated) subtag even if the code is withdrawn from the corresponding core standard. if the standard later assigns a new meaning to the withdrawn code, the corresponding subtag will still retain its old meaning.
this stability was introduced in rfc 4646.
iso 639-3 and iso 639-1.
rfc 4646 defined the concept of an "extended language subtag" (sometimes referred to as "extlang"), although no such subtags were registered at that time.
rfc 5645 and rfc 5646 added primary language subtags corresponding to iso 639-3 codes for all languages that did not already exist in the registry. in addition, codes for languages encompassed by certain macrolanguages were registered as extended language subtags. sign languages were also registered as extlangs, with the prefix "sgn". these languages may be represented either with the subtag for the encompassed language alone ("cmn" for mandarin) or with a language-extlang combination ("zh-cmn"). the first option is preferred for most purposes. the second option is called "extlang form" and is new in rfc 5646.
whole tags that were registered prior to rfc 4646 and are now classified as "grandfathered" or "redundant" (depending on whether they fit the new syntax) are deprecated in favor of the corresponding iso 639-3-based language subtag, if one exists. to list a few examples, "nan" is preferred over "zh-min-nan" for min nan chinese; "hak" is preferred over "i-hak" and "zh-hakka" for hakka chinese; and "ase" is preferred over "sgn-us" for american sign language.
iso 639-5 and iso 639-1/2.
iso 639-5 defines language collections with alpha-3 codes in a different way than they were initially encoded in iso 639-2 (including one code already present in iso 639-1, bihari coded inclusively as "bh" in iso 639-1 and "bih" in iso 639-2). specifically, the language collections are now all defined in iso 639-5 as inclusive, rather than some of them being defined exclusively. this means that language collections have a broader scope than before, in some cases where they could encompass languages that were already encoded separately within iso 639-2.
for example, the iso 639-2 code "afa" was previously associated with the name "afro-asiatic (other)", excluding languages such as arabic that already had their own code. in iso 639-5, this collection is named "afro-asiatic languages" and includes all such languages. iso 639-2 changed the exclusive names in 2009 to match the inclusive iso 639-5 names.
to avoid breaking implementations that may still depend on the older (exclusive) definition of these collections, iso 639-5 defines a grouping type attribute for all collections that were already encoded in iso 639-2 (such grouping type is not defined for the new collections added only in iso 639-5).
bcp 47 defines a "scope" property to identify subtags for language collections. however, it does not define any given collection as inclusive or exclusive, and does not use the iso 639-5 grouping type attribute, although the description fields in the language subtag registry for these subtags match the iso 639-5 (inclusive) names. as a consequence, bcp 47 language tags that include a primary language subtag for a collection may be ambiguous as to whether the collection is intended to be inclusive or exclusive.
iso 639-5 does not define precisely which languages are members of these collections; only the hierarchical classification of collections is defined, using the inclusive definition of these collections. because of this, rfc 5646 does not recommend the use of subtags for language collections for most applications, although they are still preferred over subtags whose meaning is even less specific, such as "multiple languages" and "undetermined".
in contrast, the classification of individual languages within their macrolanguage is standardized, in both iso 639-3 and the language subtag registry.
iso 15924, iso/iec 10646 and unicode.
script subtags were first added to the language subtag registry when rfc 4646 was published, from the list of codes defined in iso 15924. they are encoded in the language tag after primary and extended language subtags, but before other types of subtag, including region and variant subtags.
some primary language subtags are defined with a property named "suppress-script" which indicates the cases where a single script can usually be assumed by default for the language, even if it can be written with another script. when this is the case, it is preferable to omit the script subtag, to improve the likelihood of successful matching. a different script subtag can still be appended to make the distinction when necessary. for example, "yi" is preferred over "yi-hebr" in most contexts, because the hebrew script subtag is assumed for the yiddish language.
as another example, "zh-hans-sg" may be considered equivalent to "zh-hans", because the region code is probably not significant; the written form of chinese used in singapore uses the same simplified chinese characters as in other countries where chinese is written. however, the script subtag is maintained because it is significant.
note that iso 15924 includes some codes for script variants (for example, "hans" and "hant" for simplified and traditional forms of chinese characters) that are unified within unicode and iso/iec 10646. these script variants are most often encoded for bibliographic purposes, but are not always significant from a linguistic point of view (for example, "latf" and "latg" script codes for the fraktur and gaelic variants of the latin script, which are mostly encoded with regular latin letters in unicode and iso/iec 10646). they may occasionally be useful in language tags to expose orthographic or semantic differences, with different analysis of letters, diacritics, and digraphs/trigraphs as default grapheme clusters, or differences in letter casing rules.
iso 3166-1 and un m.49.
two-letter region subtags are based on codes assigned, or "exceptionally reserved", in iso 3166-1. if the iso 3166 maintenance agency were to reassign a code that had previously been assigned to a different country, the existing bcp 47 subtag corresponding to that code would retain its meaning, and a new region subtag based on un m.49 would be registered for the new country. un m.49 is also the source for numeric region subtags for geographical regions, such as codice_1 for south america.
the un m.49 codes for economic regions are not allowed.
region subtags are used to specify the variety of a language "as used in" a particular region. they are appropriate when the variety is regional in nature, and can be captured adequately by identifying the countries involved, as when distinguishing british english ("en-gb") from american english ("en-us"). when the difference is one of script or script variety, as for simplified versus traditional chinese characters, it should be expressed with a script subtag instead of a region subtag; in this example, "zh-hans" and "zh-hant" should be used instead of "zh-cn" and "zh-tw".
when a distinct language subtag exists for a language that could be considered a regional variety, it is often preferable to use the more specific subtag instead of a language-region combination. for example, "ar-dz" (arabic as used in algeria) may be better expressed as "arq" for algerian spoken arabic.
extensions.
"extension subtags" (not to be confused with "extended language subtags") allow additional information to be attached to a language tag that does not necessarily serve to identify a language. one use for extensions is to encode locale information, such as calendar and currency.
extension subtags are composed of multiple hyphen-separated character strings, starting with a single character (other than "x"), called a "singleton". each extension is described in its own ietf rfc, which identifies a registration authority to manage the data for that extension. iana is responsible for allocating singletons.
two extensions have been assigned as of january 2014.
extension t (transformed content).
extension t allows a language tag to include information on how the tagged data was transliterated, transcribed, or otherwise transformed. for example, the tag "en-t-jp" could be used for content in english that was translated from the original japanese. additional substrings could indicate that the translation was done mechanically, or in accordance with a published standard.
extension t is described in the informational rfc 6497, published in february 2012. the registration authority is the unicode consortium.
extension u (unicode locale).
extension u allows a wide variety of locale attributes found in the common locale data repository (cldr) to be embedded in language tags. these attributes include country subdivisions, calendar and time zone data, collation order, currency, number system, and keyboard identification.
some examples include:
extension u is described in the informational rfc 6067, published in december 2010. the registration authority is the unicode consortium.

