Connect+Documentation
ExtensionsAPI reference

connect.i18n

Localised messages, UI/accept languages, and language detection.

Localised messages from your own _locales/<lang>/messages.json, plus language introspection and detection. No capability.

  • Capability: none
  • Namespace: connect.i18n

Walkthrough

Localise a string.

  1. Set default_locale in the manifest and add message files:
    // _locales/en/messages.json
    { "greeting": { "message": "Hello $NAME$!", "placeholders": { "NAME": { "content": "$1" } } } }
  2. Look it up with substitutions:
    await connect.i18n.getMessage('greeting', ['World']); // "Hello World!"
  3. Adapt to the user with getUILanguage / getAcceptLanguages, or classify text with detectLanguage.

Methods

i18n.getMessage(key, substitutions?)

The localised message for key.

How to use it

  1. Add the key to your _locales/<lang>/messages.json.
  2. Call getMessage(key, subs); a missing key returns "".

Signatureconnect.i18n.getMessage(key, substitutions?)

Parameters

ParameterTypeRequiredDescription
keystringyesMessage key. Missing key → "" (Chrome parity).
substitutionsstring | string[]noFill $1…$9 / named $PLACEHOLDER$.

ReturnsPromise<string> in the UI language (region → base → default_locale).

await connect.i18n.getMessage('greeting', ['World']); // "Hello World!"

i18n.getUILanguage()

How to use it

  1. Call it to read the app's UI locale (e.g. to pick a matching format).

Signatureconnect.i18n.getUILanguage() · ReturnsPromise<string>, e.g. "en-US".

i18n.getAcceptLanguages()

The user's preferred languages from the OS, most-preferred first, deduped (falls back to the UI language).

How to use it

  1. Call it to choose content in the user's most-preferred language you support.

Signatureconnect.i18n.getAcceptLanguages() · ReturnsPromise<string[]>.

i18n.detectLanguage(text)

Detect the language of a string.

How to use it

  1. Pass a chunk of text.
  2. Read languages[0].language; gate on isReliable for short text.

Signatureconnect.i18n.detectLanguage(text)

Parameters

ParameterTypeRequiredDescription
textstringyesThe text to classify.

ReturnsPromise<{ isReliable, languages: [{ language, percentage }] }> — top 3, best first; language is a 2-letter code where one exists.

Edge cases

  • isReliable is false for very short text — it still answers, but don't lean on it.
const { isReliable, languages } = await connect.i18n.detectLanguage('Bonjour le monde');
if (isReliable) console.log(languages[0].language); // 'fr'

Notes

  • getMessage follows the same region → base → default fallback chain the shell UI uses, so a partial translation degrades gracefully.

On this page