- Version
- 1.0.0
- License
- MIT
- Requires
- object
- langMap
- langTranslations
- convertTime
- Source
- Locale.js, line 19
Constructor
new Locale(player, parent, optionsopt)
Creates a new instance of the Locale component.
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
player |
Player |
Reference to the VisionPlayer instance. |
|||||||||
parent |
Player |
Reference to the parent instance. |
|||||||||
options |
Object | optional |
Additional options.
|
Members
private #config :Object
Holds the instance configuration for this component.
| Name | Type | Attributes | Description |
|---|---|---|---|
lang
|
string | optional | Sets the default UI language. Affects which locale is used for translation. If not present, the player tries to find the best suitable locale based on browser language, with a final fallback to |
private #player :Player
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.
Methods
private #translate(translatePath, vars) → string
Returns a translation based on the delivered translation path.
| Name | Type | Description |
|---|---|---|
translatePath |
string |
Path to the desired translation. Path segments are separated by ".", for example "tree.subtree.property". |
vars |
Object |
Additional vars to translate. |
private #getLocalizedTime(timeArg) → string
Returns a localized string representing a time duration in hours, minutes, and seconds.
This method takes a time value in seconds and converts it to a human-readable format,
applying language-specific singular or plural units for hours, minutes, and seconds,
depending on the current locale. If null or undefined is passed, an empty string is returned.
| Name | Type | Description |
|---|---|---|
timeArg |
string | number | convertTime~smpteFormat |
The input value in one of the three accepted formats: seconds, a string or a module:src/core/Player~smpteFormat Object. |
private #getNativeLang(lang) → string
Translates a language identifier (ISO 639-3 or legacy code) to its native language name.
Accepts ISO 639-3 codes (e.g. 'deu'), legacy codes (e.g. 'ger'), or 2-letter codes (if present in langMap).
Returns the native name of the language as displayed in UI elements like language or subtitle menus.
If no translation is available, the original language code is returned.
| Name | Type | Description |
|---|---|---|
lang |
string |
The language identifier to translate. |
destroy()
This method removes all events, subscriptions and DOM nodes created by this component.
static initialize(Player)
Component initializer, called by the player automatically when adding this component. Exposes some API calls to the Player constructor.
| Name | Type | Description |
|---|---|---|
Player |
Player |
Reference to the player Constructor. |
private, static #addLocale(translations)
Adds another locale object. This can be a whole object, or just a fragment, specified by the langpath. Note* This method has to be called on the player constructor (not the instance), and only has an effect before a VisionPlayer instance is created.
| Name | Type | Description |
|---|---|---|
translations |
Object |
JSON like data structure with key / value pairs, extends the existing locale object. Make sure the language code is at the root level of the translations object, like this: |
private, static #setDefaultLocale(lang)
Sets the player locale. Note* This method has to be called on the player constructor (not the instance), and only has an effect before a VisionPlayer instance is created.
| Name | Type | Description |
|---|---|---|
lang |
string |
The language to set, represented by a (known) language code. |