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.
- Set
default_localein the manifest and add message files:// _locales/en/messages.json { "greeting": { "message": "Hello $NAME$!", "placeholders": { "NAME": { "content": "$1" } } } } - Look it up with substitutions:
await connect.i18n.getMessage('greeting', ['World']); // "Hello World!" - Adapt to the user with
getUILanguage/getAcceptLanguages, or classify text withdetectLanguage.
Methods
i18n.getMessage(key, substitutions?)
The localised message for key.
How to use it
- Add the
keyto your_locales/<lang>/messages.json. - Call
getMessage(key, subs); a missing key returns"".
Signature — connect.i18n.getMessage(key, substitutions?)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | yes | Message key. Missing key → "" (Chrome parity). |
substitutions | string | string[] | no | Fill $1…$9 / named $PLACEHOLDER$. |
Returns — Promise<string> in the UI language (region → base → default_locale).
await connect.i18n.getMessage('greeting', ['World']); // "Hello World!"i18n.getUILanguage()
How to use it
- Call it to read the app's UI locale (e.g. to pick a matching format).
Signature — connect.i18n.getUILanguage() · Returns — Promise<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
- Call it to choose content in the user's most-preferred language you support.
Signature — connect.i18n.getAcceptLanguages() · Returns — Promise<string[]>.
i18n.detectLanguage(text)
Detect the language of a string.
How to use it
- Pass a chunk of
text. - Read
languages[0].language; gate onisReliablefor short text.
Signature — connect.i18n.detectLanguage(text)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | yes | The text to classify. |
Returns — Promise<{ isReliable, languages: [{ language, percentage }] }> — top 3,
best first; language is a 2-letter code where one exists.
Edge cases
isReliableis 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
getMessagefollows the same region → base → default fallback chain the shell UI uses, so a partial translation degrades gracefully.