# cp.i18n.languageID

As per Apple's documentation, a language ID is a code which identifies either a language used across multiple regions, a dialect from a specific region, or a script used in multiple regions. See the parse function for details.

When you parse a code with the forCode function, it will result in a table that contains a reference to the approprate cp.i18n.language table, and up to one of either the matching cp.i18n.region or cp.i18n.script tables. These contain the full details for each language/regin/script, as appropriate.

You can also convert the resulting table back to the code via tostring, or the code method.


# API Overview

Functions - API calls offered directly by the extension

  • is
  • parse

Constructors - API calls which return an object, typically one that offers API methods

  • forCode
  • forLocaleID
  • forParts

Fields - Variables which can only be accessed from an object returned by a constructor

  • code
  • language
  • region
  • script

Methods - API calls which can only be made on an object returned by a constructor

  • toLocaleID

# API Documentation

# Functions

# is

Signature cp.i18n.languageID.is(thing) -> boolean
Type Function
Description Checks if the thing is a languageID instance.
Parameters
  • thing - the thing to check.
Returns
  • true if the thing is a languageID, otherwise false.
Notes None
Examples None
Source src/extensions/cp/i18n/languageID.lua line 32

# parse

Signature cp.i18n.languageID.parse(code) -> string, string, string
Type Function
Description Parses a language ID. into three possible string components
Parameters
  • code - The language ID code. Eg. "en-AU".
Returns
  • language - The two-character lower-case alpha language code.
  • script - the four-character mixed-case alpha script code.
  • region - The two-character upper-case alpha region code.
Notes
  • Parses a language ID into three possible string components:
  • ** The ISO 693-1 language code
  • ** The ISO 15924 script code
  • ** The ISO 3166-1 region code
  • This is one of the following patterns:
  • ** [language] - eg. "en", or "fr". The covers the language across all languages and scripts.
  • ** [language]-[script] - eg. "az-Arab" for Azerbaijani in Arabic script, "az-Latn" for Azerbaijani in Latin script.
  • ** [language]-[region] - eg. "en-AU" for Australian English, "fr-CA" for Canadian French, etc.
  • It will then return the matched component in three return values: language, script, region.
  • If a script is specified, the region will be nil. Eg.:
  • lua</li><li>local lang, scrpt, rgn, scrpt = languageID.parse("en-AU") -- results in "en", nil, "AU"</li><li>
Examples None
Source src/extensions/cp/i18n/languageID.lua line 45

# Constructors

# forCode

Signature cp.i18n.languageID.forCode(code) -> cp.i18n.languageID, string
Type Constructor
Description Creates, or retrieves from the cache, a languageID instance for the specified code.
Parameters
  • code - The language ID code.
Returns
  • The matching languageID, or nil if the language ID couldn't be found.
  • The error message, or nil if there was no problem.
Notes
  • If the code can't be parsed, or if the actual language/region/script codes don't exist, nil is returned.
Examples None
Source src/extensions/cp/i18n/languageID.lua line 148

# forLocaleID

Signature cp.i18n.languageID.forLocaleID(code[, prioritiseScript]) -> cp.i18n.languageID, string
Type Constructor
Description Creates, or retrieves from the cache, a languageID instance for the specified cp.i18n.localeID.
Parameters
  • locale - The localeID to convert
  • prioritiseScript - If set to true and the locale has both a region and script then the script code will be used.
Returns
  • The languageID for the locale, or nil
  • The error message if there was a problem.
Notes
  • Language IDs can only have either a script or a region, so if the locale has both, this will priortise the region by default. You can set prioritiseScript to true to use script instead.
  • If only one or the other is set in the locale, prioritiseScript is ignored.
Examples None
Source src/extensions/cp/i18n/languageID.lua line 165

# forParts

Signature cp.i18n.languageID.forParts(languageCode[, scriptCode[, regionCode]]) -> cp.i18n.languageID
Type Constructor
Description Returns a languageID with the specified parts.
Parameters
  • languageCode - Language code
  • scriptCode - Optional Script code
  • regionCode - Optional Region Code
Returns
  • A cp.i18n.languageID object.
Notes None
Examples None
Source src/extensions/cp/i18n/languageID.lua line 84

# Fields

# code

Signature cp.i18n.languageID.code <string>
Type Field
Description The language ID code.
Notes None
Source src/extensions/cp/i18n/languageID.lua line 217

# language

Signature cp.i18n.languageID.language <cp.i18n.language>
Type Field
Description The matching language details.
Notes None
Source src/extensions/cp/i18n/languageID.lua line 221

# region

Signature cp.i18n.languageID.region <cp.i18n.region>
Type Field
Description The matching region details, if appropriate. Will be nil if no region was specified in the code.
Notes None
Source src/extensions/cp/i18n/languageID.lua line 225

# script

Signature cp.i18n.languageID.script <cp.i18n.script>
Type Field
Description The matching script details, if appropriate. Will be nil if no script was specified in the code.
Notes None
Source src/extensions/cp/i18n/languageID.lua line 229

# Methods

# toLocaleID

Signature cp.i18n.languageID:toLocaleID() -> cp.i18n.localeID
Type Method
Description Returns the cp.i18n.localeID equivalent for this languageID.
Parameters
  • None
Returns
  • The matching localeID.
Notes None
Examples None
Source src/extensions/cp/i18n/languageID.lua line 195