i18n API

Hint

The i18n API is inherited from Firefox, and its primary documentation is maintained by Mozilla at MDN. Thunderbird implements only the subset of functions, events, and types listed here. The MDN pages may provide further details and examples, but they may also reference features that are not supported in Thunderbird.

Use the browser.i18n infrastructure to implement internationalization across your whole app or extension.

Manifest file properties

default_locale

[default_locale]

(string, optional)

l10n_resources

[l10n_resources]

(array of string, optional)

Functions

detectLanguage(text)

– [Added in TB 47]

Detects the language of the provided text using CLD.

Parameters

text

text

(string)

User input string to be translated.

Return type (Promise)

_returns

object

LanguageDetectionResult object that holds detected langugae reliability and array of DetectedLanguage

isReliable

isReliable

(boolean)

CLD detected language reliability

languages

languages

(array of object)

array of detectedLanguage

getAcceptLanguages()

– [Added in TB 47]

Gets the accept-languages of the browser. This is different from the locale used by the browser; to get the locale, use getUILanguage().

Return type (Promise)

_returns

array of LanguageCode

Array of LanguageCode

getMessage(messageName, [substitutions])

– [Added in TB 45]

Gets the localized string for the specified message. If the message is missing, this method returns an empty string (‘’). If the format of the getMessage() call is wrong — for example, messageName is not a string or the substitutions array has more than 9 elements — this method returns undefined.

Note

Thunderbird 47 and earlier returns “??” instead of “” if the message is not found in _locales, bug 1258199 changed this act to match Chrome, landed on Thunderbird 48.

Parameters

messageName

messageName

(string)

The name of the message, as specified in the messages.json file.

substitutions

[substitutions]

(any, optional)

Substitution strings, if the message requires any.

Return type (Promise)

_returns

string

Message localized for current locale.

getPreferredSystemLanguages()

Gets the preferred locales of the operating system. This is different from the locales set in the browser; to get those, use getAcceptLanguages().

Return type (Promise)

_returns

array of LanguageCode

Array of LanguageCode

getUILanguage()

– [Added in TB 47]

Gets the browser UI language of the browser. This is different from getAcceptLanguages() which returns the preferred user languages.

Note

Thunderbird 55 and earlier returns a language tag that’s separated with the underscore character instead of hyphen, see bug 1374552.

Return type (Promise)

_returns

string

The browser UI language code such as en-US or fr-FR.

Types

LanguageCode

– [Added in TB 45]

An ISO language code such as en or fr. For a complete list of languages supported by this method, see kLanguageInfoTable. For an unknown language, und will be returned, which means that [percentage] of the text is unknown to CLD

string