LocaleHelper

Thin class which provides locale management methods. Class doesn't import other API classes and can be used separately for publishing locales before importing product classes.

Locale should be published with publishLocale method before it is available for localizing of Bryntum API classes and widgets.

Example:

LocaleHelper.publishLocale({
    localeName : 'En',
    localeDesc : 'English (US)',
    localeCode : 'en-US',
    ... (localization key:value pairs)
});

or for asynchronous loading from remote path on applying locale

LocaleHelper.publishLocale({
    localeName : 'En',
    localeDesc : 'English (US)',
    localeCode : 'en-US',
    localePath : 'https://my-server/localization/en.js'
});

Properties

3
locale: Localesreadonlystatic

Get current locale config specified by localeName. If no current locale specified, returns default En locale or first published locale or empty locale object if no published locales found.

localeName: Stringstatic

Get/set current locale name. Defaults to "En"

locales: Localesreadonlystatic

Get/set currently published locales. Returns an object with locales.

Example:

const englishLocale = LocaleHelper.locales.En;

englishLocale contains Locale object.

Functions

3

Merges all properties of provided locale objects into new locale object. Locales are merged in order they provided and locales which go later replace same properties of previous locales.

ParameterTypeDescription
localesObject

Locales to merge

Returns: Object -

Merged locale

Publishes a locale to make it available for applying. Published locales are available in locales.

Recommended usage:

LocaleHelper.publishLocale({
    localeName : 'En',
    localeDesc : 'English (US)',
    localeCode : 'en-US',
    ... (localization key:value pairs)
});

for backward compatibility (prior to 5.3.0 version):

LocaleHelper.publishLocale('En', {
    name : 'En',
    desc : 'English (US)',
    code : 'en-US',
    locale : {
        ... (localization key:value pairs)
    }
});

Publishing a locale will automatically merge it's localization keys with existing locale matching by locale name, replacing existing one with new. To replace existing locale entirely pass true to optional config parameter.

Example:

LocaleHelper.publishLocale({
    localeName : 'En',
    localeDesc : 'English (US)',
    localeCode : 'en-US',
    ... (localization key:value pairs)
}, true);
ParameterTypeDescription
nameOrConfigString | Locale

String name of locale (for example En or SvSE) or locale object

configLocale | Boolean

Locale object. Not used if locale object is passed as first method parameter. Path true value and locale object as first method parameter to publish locale without merging with existing one.

Returns: Locale -

Locale object

Removes all properties from locale that are present in the provided toTrim.

ParameterTypeDescription
localeObject

Locale to process

toTrimObject

Object enumerating properties that should be removed. When false throws exceptions in such cases.

Typedefs

3

Locale configuration object which contains locale properties alongside with localization pairs.

Example:

 {
    localeName : 'En',
    localeDesc : 'English (US)',
    localeCode : 'en-US',
    ... (localization key:value pairs)
}
ParameterTypeDescription
localeNameString

Locale name. For example: "En"

localeDescString

Locale description to be shown in locale picker list. For example: "English (US)"

localeCodeString

Locale code. Two letter locale code or two letter locale and two letter country code. For example: 'en' or 'en_US'

localePathString

Locale path for asynchronous loading using AjaxHelper get request

Object which contains key: value localization pairs. Key value may have String, Function, LocaleKeys or Object type.

Example:

{
    title   : 'Title',
    count   : number => `Count is ${number}`,
    MyClass : {
       foo : 'bar'
    }
}
ParameterTypeDescription
keyString | function | LocaleKeys | Object

localization key

Object which contains locales. Each object key represents published locale by its localeName.

Example:

// This returns English locale.
const englishLocale = LocaleHelper.locales.En;
ParameterTypeDescription
keyLocale

localization object