kango.i18n

Summary

Name Description
getMessage Returns localized message
getMessages Returns localized messages map
note:You can use this module in content scripts.

Methods

getMessage

kango.i18n.getMessage(name)

Returns localized message.

Arguments:
  • name (string) – message name
Return type:

string

Example:

kango.console.log(kango.i18n.getMessage('Hello'));

getMessages

kango.i18n.getMessages()

Returns localized messages map.

Return type:object

Example:

kango.console.log('Messages = ' + JSON.stringify(kango.i18n.getMessages()));

Internationalizing your extension

Creating locale file

Create %LocaleName%.json in common/locales directory. For Russian language e.g. common/locales/ru.json:

{
    "Logo": "Логотип",
    "Hello {name}": "Привет {name}"
}

Note

%LocaleName% is an ISO-639-1 language code.

To get localized message you should use kango.i18n.getMessage():

kango.i18n.getMessage('Logo') // Логотип
kango.i18n.getMessage('Hello {name}', {name: 'Bob'}) // Привет Bob

Setting default locale

Use default_locale key in extension_info.json file to set default locale:

{
    ...,

    "default_locale": "ru",

    ...
}

Internationalizing extension name and description

You can localize extension name and description using special locale keys __info_name__ and __info_description__.

common/locales/ru.json example:

{
    "__info_name__": "Название расширения",
    "__info_description__": "Описание расширения",
    "Logo": "Логотип",
    "Hello {name}": "Привет {name}"
}