Localization
The WebViewer UI is internationalized with i18next. Six languages ship out of the box; you can switch at runtime and add your own.
Supported languages
Translation files live in packages/webview/public/locales/ (copied to dist/locales/ on build), named translation-<lng>.json to match the i18next-http-backend load path ./locales/-.json.
| Code | Language |
|---|---|
en | English (fallback) |
zh-CN | Simplified Chinese |
zh-TW | Traditional Chinese |
ja | Japanese |
fr | French |
th | Thai |
Default/fallback: en. The selected language is persisted in localStorage under the language key.
UI APIs
UI.setLanguage(language)
Switch the UI language at runtime. Async.
/**
* @method UI.setLanguage
* @param {string} language Default supported: en, zh-CN, zh-TW, fr, th, ja.
*/
await UI.setLanguage('zh-CN');Internally: await i18next.changeLanguage(language), then store.setLanguage(language), then persists to localStorage['language']. Components consume translations via useTranslation() from i18next-vue.
UI.addLanguage(language)
Add a language resource to the available set.
UI.addLanguage({ /* language resource object */ });UI.removeLanguage(language)
Remove a language from the available set.
UI.removeLanguage('fr');UI.setLanguages(languages)
Replace the entire set of available languages.
UI.setLanguages([ /* array or object */ ]);How i18n is initialized
The active initializer is packages/webview/src/i18n.js:
- Uses
i18next+i18next-http-backend+i18next-vue. - Language selection:
localStorage['language'] || localStorage['currentLanguage'] || 'en'. - Init options:
load: 'currentOnly',returnObjects: true,fallbackLng: 'en', namespacetranslation. - Backend: loads
./locales/-.jsonvia a custom XHR requester that tolerates Android-webviewstatus 0forfile://loads. - Exposes
window.i18next = i18nextglobally and exportsi18nextPromise(awaited inApp/index.vuebefore the app renders).
packages/webview/src/i18nNext.jsis a minimal legacy variant (no HTTP backend, no localStorage) and is not imported bymain.js. It is superseded byi18n.js.
packages/webview/src/helpers/setupI18n.jsdeclares aLanguages[]catalog of 25[code, displayName]pairs andlanguageRulesmapping internal codes to i18next/dayjs locale codes — useful as a reference for the broader language catalog the SDK can be extended to support.
Examples
Switch to Japanese
await UI.setLanguage('ja');Add a custom language (sketch)
UI.addLanguage({
code: 'ko',
translations: {
'header.tools.annotate': '주석',
/* …full translation map… */
},
});
await UI.setLanguage('ko');The exact shape of the resource object follows the i18next resource structure; see
translation-en.jsonfor the full set of keys.
Related
- Getting Started — load-time options.
- API Reference