Class: shaka.ui.Localization

Constructor

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.
Source:

Members

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:

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:

LOCALE_UPDATED :string

The event name for when |insert| was called and it changed entries that could affect previously resolved values.
Type:
  • string
Source:

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:

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:

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:

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:

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:

fallbackLocale_ :string

Type:
  • string
Source:

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

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:

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:

insert(locale, localizationsnon-null, conflictResolutionopt) → {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.
Type
shaka.ui.Localization

release()

Source:

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

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:

updateCurrentMap_()

Source:

Events

LocaleChangedEvent

Properties:
Name Type Description
type string 'locale-changed'
locales Array.<string> The new set of locales that user wanted, and that were successfully found.
Source:

MissingLocalizationsEvent

Properties:
Name Type Description
type string 'unknown-localization'
locales Array.<string> The locales that the user wanted.
missing string The id of the unknown entry.
Source:

MissingLocalizationsEvent

Properties:
Name Type Description
type string 'missing-localizations'
locale string The locale that the user wanted.
missing Array.<string> The ids of the missing entries.
Source:

UnknownLocalesEvent

Properties:
Name Type Description
type string 'unknown-locales'
locales Array.<string> The locales that the user wanted but could not be found.
Source: