Skip to content

Module: src/locale/Locale

The Locale component manages the player’s translation layer. It stores and resolves locale data, enables the registration of custom locales before instance creation, and provides a runtime translation function. This component does not affect UI layout directly but underpins all text translations in UI components.

Version
1.0.0
Author
Frank Kudermann - alphanull
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.

Parameters:
Name Type Attributes Description
player Player

Reference to the VisionPlayer instance.

parent Player

Reference to the parent instance.

options Object optional

Additional options.

Parameters:
Name Type Attributes Description
apiKey symbol optional

Token for extended access to the player API.

Members

Holds the instance configuration for this component.

Properties
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 'en'..

Type
Object
Source
Locale.js, line 26

Reference to the main player instance.

Type
Player
Source
Locale.js, line 32

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.

Type
symbol
Source
Locale.js, line 39

Methods

private #translate(translatePath, vars) → string

Returns a translation based on the delivered translation path.

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

Returns

Returns the desired translation. If not found, the key itself is returned instead.

Type string
Throws

If type of vars data mismatches.

Type Error
Source
Locale.js, line 78

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.

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

Returns

Localized time string.

Type string
Source
Locale.js, line 156

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.

Parameters:
Name Type Description
lang string

The language identifier to translate.

Returns

The native name of the language, or the identifier itself if unknown.

Type string
Source
Locale.js, line 180

destroy()

This method removes all events, subscriptions and DOM nodes created by this component.

Source
Locale.js, line 191

static initialize(Player)

Component initializer, called by the player automatically when adding this component. Exposes some API calls to the Player constructor.

Parameters:
Name Type Description
Player Player

Reference to the player Constructor.

Source
Locale.js, line 227

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.

Parameters:
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: { "de": { ... } }.

Throws

Throws error when enountering invalid locale data.

Type Error
Source
Locale.js, line 241

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.

Parameters:
Name Type Description
lang string

The language to set, represented by a (known) language code.

Source
Locale.js, line 254

private, static #setLocaleConfig(lang, config)

Sets the config for a certain locale.

Parameters:
Name Type Description
lang string

The language tied to the config.

config Object

Config object, currently, specifiying rtl languages is supported.

Source
Locale.js, line 265