I18n API
chevron down
 

I18n API

gettext()

New in SDK 3.1

Look up the translation for a given message ID

Translations are sourced from PO files within the project sources PO files should be located within in a directory named i18n within the directory of the relevant component and named using a supported BCP-47 language tag. The following tags are currently supported:

  • de-DE
  • en-US
  • es-ES
  • fr-FR
  • it-IT
  • ja-JP
  • ko-KR
  • nl-NL
  • sv-SE
  • zh-CN
  • zh-TW
  • pt-BR (since 4.2)
  • id-ID (since 4.2)
  • ro-RO (since 4.2)
  • ru-RU (since 4.2)
  • pl-PL (since 4.2)
  • cs-CZ (since 4.2)
  • nb-NO (since 6.0)

For example:

  • app/i18n/en-US.po
  • companion/i18n/fr-FR.po
  • settings/i18n/jp-JP.po

PO files look like so:

msgid "hello_world"
msgstr "Hello world!"

msgid "heart_rate"
msgstr "Heart rate"
import { gettext } from "i18n";

const msgID = "my_string";
console.log(`${msgID} = ${gettext(msgID)}`);

Falls back to decreasingly specific translations before finally falling back to returning the message ID.

If a user has a locale selected for which there is no exact match supported, they will receive the supported locale within that language where possible.

For example, given a user locale of fr-CA, it will attempt the following in order:

  • Return translation from fr-FR.po (France French)
  • Return translation from developer configured default language
  • Return message ID

The default language if not explicitly set is en-US. Developers may configure the default language by setting the defaultLanguage property within the fitbit section of their package.json file.

Fallback happens on a PO file level, rather than a per message ID basis.

Additional features such as plurals and contexts are not supported at this time.

i18n.gettext(msgid: string)

Parameters

msgid: string

Message ID string to look up