Constructor
new LanguageUtils()
A set of language utility functions.
- Source:
Members
(private, static, constant, non-null) isoMap_ :Map.<string, string>
A map from 3-letter language codes (ISO 639-2) to 2-letter language codes
(ISO 639-1) for all languages which have both in the registry.
Type:
- Map.<string, string>
- Source:
Methods
(static) areLanguageCompatible(locale1, locale2) → {boolean}
Check if |locale1| and |locale2| are language-compatible.
Language compatible is when the language component of each locale matches.
This means that no matter what region they have (or don't have) as long as
the language components match, they are language-compatible.
Examples:
Locale A | Locale B | Language-Compatible
-----------------------------------------
en-US | en-US | true
en-US | en | true
en-US | en-CA | true
en-CA | fr-CA | false
Parameters:
Name | Type | Description |
---|---|---|
locale1 |
string | |
locale2 |
string |
- Source:
Returns:
- Type
- boolean
(static) areLocaleCompatible(locale1, locale2) → {boolean}
Check if |locale1| and |locale2| are locale-compatible.
Locale-compatible is defined as all components in each locale match. Since
we only respect the language and region components, we only check that
the language and region components match.
Examples:
Locale A | Locale B | Locale Compatible
---------------------------------------
en-US | en-US | true
en | en-US | false
en-US | en-CA | false
Parameters:
Name | Type | Description |
---|---|---|
locale1 |
string | |
locale2 |
string |
- Source:
Returns:
- Type
- boolean
(static) areSiblings(a, b) → {boolean}
Check if two language codes are siblings. Language codes are siblings if
they share the same base language while neither one is the base language.
For example, "en-US" and "en-CA" are siblings but "en-US" and "en" are not
siblings.
Parameters:
Name | Type | Description |
---|---|---|
a |
string | |
b |
string |
- Source:
Returns:
- Type
- boolean
(private, static) disassembleLocale_(locale) → (non-null) {Array.<string>}
Take a locale string and break it into its component. Check that each
component matches what we would expect internally for locales. This
should ONLY be used to verify locales that have been normalized.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string |
- Source:
Returns:
- Type
- Array.<string>
(static) findClosestLocale(target, searchSpacenon-null) → (nullable) {string}
Find the locale in |searchSpace| that comes closest to |target|. If no
locale is found to be close to |target|, then |null| will be returned.
Parameters:
Name | Type | Description |
---|---|---|
target |
string | |
searchSpace |
Iterable.<string> |
- Source:
Returns:
- Type
- string
(static) getBase(lang) → {string}
Get the normalized base language for a language code.
Parameters:
Name | Type | Description |
---|---|---|
lang |
string |
- Source:
Returns:
- Type
- string
(static) getLocaleForText(stream) → {string}
Get the normalized language of the given text stream. Will return 'und' if
a language is not found on the text stream.
This should always be used to get the language from a text stream.
Parameters:
Name | Type | Description |
---|---|---|
stream |
shaka.extern.Stream |
- Source:
Returns:
- Type
- string
(static) getLocaleForVariant(variant) → {string}
Get the normalized locale for the given variant. This will look through
the variant to find the locale that represents the content in the variant.
This will return 'und' if no language can be found.
This should always be used to get the locale from a variant.
Parameters:
Name | Type | Description |
---|---|---|
variant |
shaka.extern.Variant |
- Source:
Returns:
- Type
- string
(static) isParentOf(possibleParent, possibleChild) → {boolean}
Check if |possibleParent| is the parent locale of |possibleChild|. Because
we do not support dialects, the parent-child relationship is a lot simpler.
In a parent child relationship:
- The parent and child have the same language-component
- The parent has no region-component
- The child has a region-component
Example:
Locale A | Locale B | Is A The parent of B?
--------------------------------------------
en-US | en-US | no
en-US | en | no
en | en-US | yes
en | en | no
en | fr | no
Parameters:
Name | Type | Description |
---|---|---|
possibleParent |
string | |
possibleChild |
string |
- Source:
Returns:
- Type
- boolean
(static) isSiblingOf(localeA, localeB) → {boolean}
Check if |localeA| shares the same parent with |localeB|. Since we don't
support dialect, we will only look at language and region. For two locales
to be siblings:
- Both must have language-components
- Both must have region-components
- Both must have the same language-component
Example:
Locale A | Locale B | Siblings?
--------------------------------------------
en-US | en-US | yes
en-US | en-CA | yes
en-US | en | no
en | en-US | no
en | en | no
en | fr | no
Parameters:
Name | Type | Description |
---|---|---|
localeA |
string | |
localeB |
string |
- Source:
Returns:
- Type
- boolean
(static) normalize(locale) → {string}
Normalize a locale. This will take a locale and canonicalize it to a state
that we are prepared to work with.
We only support with:
- language
- language-REGION
If given a dialect, we will discard it. We will convert any 3-character
codes to 2-character codes. We will force language codes to lowercase and
region codes to uppercase.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string |
- Source:
Returns:
- Type
- string