Jump to content

Manual:Language/BCP-47

From mediawiki.org

IETF BCP-47 is a standard for language codes. It allows for many different combinations of subtags, including private-use subtags, to support identification by language (ISO 639) and optionally, by writing system (ISO 15924), region/country (ISO 3166) and/or dialect.

MediaWiki-internal language codes are less extensive: they are a subset of ISO 639-3 and 639-1 (see Names.php) in addition to custom tags such as qqx and possible additions registered through $wgExtraLanguageNames . Another difference is that BCP-47 codes are case-insensitive and can be mixed-case, while MediaWiki-internal codes are case-sensitive and usually lowercase.

MediaWiki support for BCP-47

[edit]
  • MediaWiki provides various means of translating a language code into a BCP47-compliant one. This normalisation is typically done for use in HTML lang attributes.
  • By default, MediaWiki-internal codes support a subset of BCP-47 codes, especially in the choice of tags for primary languages (ISO 639).
  • MediaWiki also allows site admins to register additional BCP-47 codes by having them added to the $wgExtraLanguageNames config setting. Mixed-case tags are not supported but if necessary, you can use LanguageCode::bcp47() (below) to retrieve the normalised version.
  • MediaWiki does not offer validation for BCP-47 codes, but LanguageCode::isWellFormedLanguageTag() can be used to check for well-formedness.

Resources in MediaWiki core

[edit]

PHP

[edit]
  • Bcp47Code is a Wikimedia library used by MediaWiki (1.40+) to provide a simple interface representing a language object which can be represented by a BCP-47 code. It is used between Parsoid and MediaWiki core in order to allow Parsoid to manipulate core Language objects without exposing the full details of these objects to Parsoid.
  • The LanguageCode class contains various methods for returning the BCP-47 version of a language code.
    • bcp47() – accepts a language code and returns the normalised IETF BCP-47 tag.


API

[edit]

See e.g. API:Languageinfo

Wikitext

[edit]

Since 1.43, wiki users can use the parser function {{#bcp47:...}} to retrieve the BCP-47 version for the given language code. See also Scribunto below.

Extensions

[edit]

Provides a Lua function, mw.language:toBcp47Code, to return the standard BCP-47 language code for a given language object, as appropriate for use in HTML.

See https://www.semantic-mediawiki.org/wiki/Help:Special_property_Language_code

Has broad support for BCP-47. Example: d:Lexeme:L1011590

See also

[edit]