Constructor
(export) new Localization(fallbackLocale)
Parameters:
Name | Type | Description |
---|---|---|
fallbackLocale |
string | The fallback locale that should be used. It will be assumed that this locale should have entries for just about every request. |
- Implements:
- EventTarget
- Source:
Members
(export, static) ConflictResolution :number
An enum for how the localization system should resolve conflicts between old
translations and new translations.
Type:
- number
Properties:
Name | Value | Type | Description |
---|---|---|---|
USE_OLD |
0 | number | |
USE_NEW |
1 | number |
- Source:
(static, constant) LOCALE_CHANGED :string
The event name for when a new locale has been requested and any previously
resolved values should be updated.
Type:
- string
- Source:
(static, constant) LOCALE_UPDATED :string
The event name for when |insert| was called and it changed entries that could
affect previously resolved values.
Type:
- string
- Source:
(static, constant) MISSING_LOCALIZATIONS :string
The event name for when entries are missing from the user's preferred
locale, but we were able to find an entry in a related locale or the fallback
locale.
Type:
- string
- Source:
(static, constant) UNKNOWN_LOCALES :string
The event name for when locales were requested, but we could not find any
entries for them. The localization system will continue to use the closest
matches it has.
Type:
- string
- Source:
(static, constant) UNKNOWN_LOCALIZATION :string
The event name for when an entry could not be found in the preferred locale,
related locales, or the fallback locale.
Type:
- string
- Source:
(private, non-null) currentLocales_ :Set.<string>
The locales that were used when creating |currentMap_|. Since we don't
have anything when we first initialize, an empty set means "no
preference".
Type:
- Set.<string>
- Source:
(private, non-null) currentMap_ :Map.<string, string>
The current mappings that will be used when requests are made. Since
nothing has been loaded yet, there will be nothing in this map.
Type:
- Map.<string, string>
- Source:
(private, non-null) events_ :EventTarget
The event target that we will wrap so that we can fire events
without having to manage the listeners directly.
Type:
- EventTarget
- Source:
(private, non-null) localizations_ :Map.<string, !Map.<string, string>>
A map of maps where:
- The outer map is a mapping from locale code to localizations.
- The inner map is a mapping from id to localized text.
Type:
- Map.<string, !Map.<string, string>>
- Source:
Methods
(private, static) findMissingKeys_(mapnon-null, keysnon-null, missingnon-null)
Go through a map and add all the keys that are in |keys| but not in
|map| to |missing|.
Parameters:
Name | Type | Description |
---|---|---|
map |
Map.<string, string> | |
keys |
Iterable.<string> | |
missing |
Set.<string> |
- Source:
(export) addEventListener()
- Source:
(export) changeLocale(localesnon-null)
Request the localization system to change which locale it serves. If any of
of the preferred locales cannot be found, the localization system will fire
an event identifying which locales it does not know. The localization
system will then continue to operate using the closest matches it has.
Parameters:
Name | Type | Description |
---|---|---|
locales |
Iterable.<string> | The locale codes for the requested locales in order of preference. |
- Source:
(export) dispatchEvent()
- Source:
(export) insert(locale, localizationsnon-null, conflictResolutionopt) → (non-null) {shaka.ui.Localization}
Insert a set of localizations for a single locale. This will amend the
existing localizations for the given locale.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
locale |
string | The locale that the localizations should be added to. | |
localizations |
Map.<string, string> | A mapping of id to localized text that should used to modify the internal collection of localizations. | |
conflictResolution |
shaka.ui.Localization.ConflictResolution |
<optional> |
The strategy used to resolve conflicts when the id of an existing entry matches the id of a new entry. Default to |USE_NEW|, where the new entry will replace the old entry. |
- Source:
Returns:
Returns |this| so that calls can be chained.
(export) removeEventListener()
- Source:
(export) resolve(id) → {string}
Request the localized string under the given id. If there is no localized
version of the string, then the fallback localization will be given
("en" version). If there is no fallback localization, a non-null empty
string will be returned.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id for the localization entry. |
- Source:
Returns:
- Type
- string
(export) resolveDictionary(dictionarynon-null)
Set the value under each key in |dictionary| to the resolved value.
Convenient for apps with some kind of data binding system.
Equivalent to:
for (const key of dictionary.keys()) {
dictionary.set(key, localization.resolve(key));
}
Parameters:
Name | Type | Description |
---|---|---|
dictionary |
Map.<string, string> |
- Source:
(private) updateCurrentMap_()
- Source:
Type Definitions
MissingLocalizationsEvent
Type:
- {'locales': !Array.<string>, 'missing': !Array.<string>}
Properties:
Name | Type | Description |
---|---|---|
locale |
string | The locale that the user wanted. |
missing |
Array.<string> | The ids of the missing entries. |
- Source:
UnknownLocalesEvent
Type:
- {'locales': !Array.<string>}
Properties:
Name | Type | Description |
---|---|---|
locales |
Array.<string> | The locales that the user wanted but could not be found. |
- Source:
UnknownLocalizationEvent
Type:
- {'locales': !Array.<string>, 'missing': string}
Properties:
Name | Type | Description |
---|---|---|
locales |
Array.<string> | The locales that the user wanted. |
missing |
string | The id of the unknown entry. |
- Source: