Locale
Represents the localization services.
Properties
contentLanguage : stringreadonlymodule:utils/locale~Locale#contentLanguageThe editor content language code in the ISO 639-1 format.
Usually the same as the editor language, it can be customized by passing an optional argument to the
Localeconstructor.contentLanguageDirection : LanguageDirectionreadonlymodule:utils/locale~Locale#contentLanguageDirectionText direction of the editor content language.
If the content language was passed directly to the
Localeconstructor, this property represents the direction of that language.If the editor content language was derived from the editor language, the content language direction is the same as the UI language direction.
The value is either
'ltr'or'rtl'.t : LocaleTranslatereadonlymodule:utils/locale~Locale#tTranslates the given message to the
uiLanguage. This method is also available inEditorandView.This method's context is statically bound to the
Localeinstance and should always be called as a function:const t = locale.t; t( 'Label' );Copy codeThe message can be either a string or an object implementing the
Messageinterface.The message may contain placeholders (
%<index>) for value(s) that are passed as avaluesparameter. For an array of values, the%<index>will be changed to an element of that array at the given index. For a single value passed as the second argument, only the%0placeholders will be changed to the provided value.t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] ); t( 'Created file "%0", fileName );Copy codeThe message supports plural forms. To specify the plural form, use the
pluralproperty. Singular or plural form will be chosen depending on the first value from the passedvalues. The value of thepluralproperty is used as a default plural translation when the translation for the target language is missing.t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language. t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language. t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language. t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language. t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language. t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.Copy code- The message should provide an ID using the
idproperty when the message strings are not unique and their translations should be different.
translate( 'en', { string: 'image', id: 'ADD_IMAGE' } ); translate( 'en', { string: 'image', id: 'AN_IMAGE' } );Copy code- The message should provide an ID using the
translations : Translations | undefinedmodule:utils/locale~Locale#translationsObject that contains translations.
uiLanguage : stringreadonlymodule:utils/locale~Locale#uiLanguageThe editor UI language code in the ISO 639-1 format.
If the content language was not specified in the
Localeconstructor, it also defines the language of the content.uiLanguageDirection : LanguageDirectionreadonlymodule:utils/locale~Locale#uiLanguageDirectionText direction of the editor UI language. Either
'ltr'or'rtl'.
Methods
constructor( options = { [options.contentLanguage], [options.translations], [options.uiLanguage] } )module:utils/locale~Locale#constructorCreates a new instance of the locale class. Learn more about configuring the language of the editor.
Parameters
options : objectLocale configuration.
Properties[ options.contentLanguage ] : stringThe editor content language code in the ISO 639-1 format. If not specified, the same as
options.language. SeecontentLanguage.[ options.translations ] : ArrayOrItem<Translations>Translations passed as a editor config parameter.
[ options.uiLanguage ] : stringThe editor UI language code in the ISO 639-1 format. See
uiLanguage.Defaults to
'en'
Defaults to
{}
_t( message, values ) → stringprivatemodule:utils/locale~Locale#_t