≡ i18n API
Use the browser.i18n infrastructure to implement internationalization across your whole app or extension.
.. rst-class:: api-main-section
.. api-member:: :name: [``default_locale``] :type: (string, optional)
.. api-member:: :name: [``l10n_resources``] :type: (array of string, optional)
.. rst-class:: api-main-section
.. api-section-annotation-hack::
Detects the language of the provided text using CLD.
.. api-header:: :label: Parameters .. api-member:: :name: ``text`` :type: (string) User input string to be translated.
.. api-header:: :label: Return type (`Promise`_) .. api-member:: :type: object LanguageDetectionResult object that holds detected langugae reliability and array of DetectedLanguage .. api-member:: :name: ``isReliable`` :type: (boolean) CLD detected language reliability .. api-member:: :name: ``languages`` :type: (array of object) array of detectedLanguage .. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
.. api-section-annotation-hack::
Gets the accept-languages of the browser. This is different from the locale used by the browser; to get the locale, use :ref:`i18n.getUILanguage`.
.. api-header:: :label: Return type (`Promise`_) .. api-member:: :type: array of :ref:`i18n.LanguageCode` Array of LanguageCode .. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
.. api-section-annotation-hack::
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.
.. api-header:: :label: Parameters .. api-member:: :name: ``messageName`` :type: (string) The name of the message, as specified in the :code:`$(topic:i18n-messages)[messages.json]` file. .. api-member:: :name: [``substitutions``] :type: (any, optional) Substitution strings, if the message requires any.
.. api-header:: :label: Return type (`Promise`_) .. api-member:: :type: string Message localized for current locale. .. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
.. api-section-annotation-hack::
Gets the browser UI language of the browser. This is different from :ref:`i18n.getAcceptLanguages` which returns the preferred user languages.
.. api-header:: :label: Return type (`Promise`_) .. api-member:: :type: string The browser UI language code such as en-US or fr-FR. .. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
.. rst-class:: api-main-section
.. rst-class:: api-main-section
.. api-section-annotation-hack::
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
.. api-header:: :label: string