In this namespace you will find classes and methods for handling locale and localized texts.
Classes
Namespaces
Members
# (static, constant) localeStringSymbol :symbol
Type:
- symbol
# (static, constant) propertiesSymbol :symbol
Type:
- symbol
Methods
# (static) parseLocale(locale) → {Locale}
Parse local according to rfc4646 standard
Limitations: The regex cannot handle multiple variants or private.
You can call the method via the monster namespace Monster.I18n.createLocale()
.
<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/i18n/locale.js';
console.log(new Monster.I18n.createLocale())
</script>
Alternatively, you can also integrate this function individually.
<script type="module">
import {createLocale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/i18n/locale.js';
console.log(createLocale())
</script>
RFC
The syntax of the language tag in ABNF [RFC4234] is:
Language-Tag = langtag
/ privateuse ; private use tag
/ grandfathered ; grandfathered registrations
langtag = (language
["-" script]
["-" region]
*("-" variant)
*("-" extension)
["-" privateuse])
language = (2*3ALPHA [ extlang ]) ; shortest ISO 639 code
/ 4ALPHA ; reserved for future use
/ 5*8ALPHA ; registered language subtag
extlang = *3("-" 3ALPHA) ; reserved for future use
script = 4ALPHA ; ISO 15924 code
region = 2ALPHA ; ISO 3166 code
/ 3DIGIT ; UN M.49 code
variant = 5*8alphanum ; registered variants
/ (DIGIT 3alphanum)
extension = singleton 1*("-" (2*8alphanum))
singleton = %x41-57 / %x59-5A / %x61-77 / %x79-7A / DIGIT
; "a"-"w" / "y"-"z" / "A"-"W" / "Y"-"Z" / "0"-"9"
; Single letters: x/X is reserved for private use
privateuse = ("x"/"X") 1*("-" (1*8alphanum))
grandfathered = 1*3ALPHA 1*2("-" (2*8alphanum))
; grandfathered registration
; Note: i is the only singleton
; that starts a grandfathered tag
alphanum = (ALPHA / DIGIT) ; letters and numbers
Figure 1: Language Tag ABNF
Parameters:
Name | Type | Description |
---|---|---|
locale |
string |
- Since:
- 1.14.0
- Copyright:
- schukai GmbH
Throws:
-
-
value is not a string
- Type
- TypeError
-
-
-
unsupported locale
- Type
- Error
-
Returns:
- Type
- Locale
Type Definitions
# LocaleMap
Type:
- Object
Properties
Name | Type | Description |
---|---|---|
language |
string | |
script |
string | |
region |
string | |
variants |
string | |
extlang |
string | |
privateUse |
string |