Locale

Api-class icon class

Represents the localization services.

Properties

  • Chevron-right icon

    contentLanguage : string
    readonly

    The 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 Locale constructor.

  • Chevron-right icon

    Text direction of the editor content language.

    If the content language was passed directly to the Locale constructor, 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'.

  • Chevron-right icon

    t : LocaleTranslate
    readonly

    Translates the given message to the uiLanguage. This method is also available in Editor and View.

    This method's context is statically bound to the Locale instance and should always be called as a function:

    const t = locale.t;
    t( 'Label' );
    
    Copy code

    The message can be either a string or an object implementing the Message interface.

    The message may contain placeholders (%<index>) for value(s) that are passed as a values parameter. 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 %0 placeholders will be changed to the provided value.

    const t = locale.t;
    t( 'Label' );
    
    Copy code

    The message supports plural forms. To specify the plural form, use the plural property. Singular or plural form will be chosen depending on the first value from the passed values. The value of the plural property is used as a default plural translation when the translation for the target language is missing.

    const t = locale.t;
    t( 'Label' );
    
    Copy code
    • The message should provide an ID using the id property when the message strings are not unique and their translations should be different.
    const t = locale.t;
    t( 'Label' );
    
    Copy code
  • Chevron-right icon

    translations : Translations | undefined

    Object that contains translations.

  • Chevron-right icon

    uiLanguage : string
    readonly

    The editor UI language code in the ISO 639-1 format.

    If the content language was not specified in the Locale constructor, it also defines the language of the content.

  • Chevron-right icon

    Text direction of the editor UI language. Either 'ltr' or 'rtl'.

Methods

  • Chevron-right icon

    constructor( options = { [options.contentLanguage], [options.translations], [options.uiLanguage] } )

    Creates a new instance of the locale class. Learn more about configuring the language of the editor.

    Parameters

    options : object

    Locale configuration.

    Properties
    [ options.contentLanguage ] : string

    The editor content language code in the ISO 639-1 format. If not specified, the same as options.language. See contentLanguage.

    [ options.translations ] : ArrayOrItem<Translations>

    Translations passed as a editor config parameter.

    [ options.uiLanguage ] : string

    The editor UI language code in the ISO 639-1 format. See uiLanguage.

    Defaults to 'en'

    Defaults to {}

  • Chevron-right icon

    _t( message, values ) → string
    Lock icon private

    An unbound version of the t method.

    Parameters

    message : string | Message
    values : string | number | readonly Array<string | number>

    Defaults to []

    Returns

    string