Module

utils/translation-service

@ckeditor/ckeditor5-utils/src/translation-service

module

Filtering

Functions

  • _clear()

    protected static

    Clears dictionaries for test purposes.

  • add( language, translations )

    static

    Adds translations to existing ones. These translations will later be available for the translate() function.

    add( 'pl', {
        'OK': 'OK',
        'Cancel [context: reject]': 'Anuluj'
    } );

    If you cannot import this function from this module (e.g. because you use a CKEditor 5 build), then you can still add translations by extending the global window.CKEDITOR_TRANSLATIONS object by using a function like the one below:

    function addTranslations( language, translations ) {
        if ( !window.CKEDITOR_TRANSLATIONS ) {
            window.CKEDITOR_TRANSLATIONS = {};
        }
    
        const dictionary = window.CKEDITOR_TRANSLATIONS[ language ] || ( window.CKEDITOR_TRANSLATIONS[ language ] = {} );
    
        // Extend the dictionary for the given language.
        Object.assign( dictionary, translations );
    }

    Parameters

    language : String

    Target language.

    translations : Object.<String, String>

    Translations which will be added to the dictionary.

  • translate( language, translationKey ) → String

    static

    Translates string if the translation of the string was previously added to the dictionary. See Translation Service. This happens in a multi-language mode were translation modules are created by the bundler.

    When no translation is defined in the dictionary or the dictionary doesn't exist this function returns the original string without the '[context: ]' (happens in development and single-language modes).

    In a single-language mode (when values passed to t() were replaced with target language strings) the dictionary is left empty, so this function will return the original strings always.

    translate( 'pl', 'Cancel [context: reject]' );

    Parameters

    language : String

    Target language.

    translationKey : String

    String that will be translated.

    Returns

    String

    Translated sentence.