Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Localization ​

The WebViewer UI is internationalized with i18next. Six languages ship out of the box; you can switch at runtime, change translations and add your own languages. Each WebViewer instance has its own i18next instance.

Supported languages ​

Translation files are in webviewer/locales/, named translation-<lng>.json. They are loaded from {uiPath}locales/ when a language is used.

CodeLanguage
enEnglish (fallback)
zh-CNSimplified Chinese
zh-TWTraditional Chinese
jaJapanese
frFrench
thThai

Default/fallback: en. The initial language is the defaultLanguage option. The selected language is saved for the instance and restored next time.

UI APIs ​

UI.setLanguage(language) ​

Switch the UI language at runtime. Returns a Promise that resolves when the language is ready.

javascript
/**
 * @method UI.setLanguage
 * @param {string} language Default supported: en, zh-CN, zh-TW, fr, th, ja.
 * @returns {Promise<void>}
 */
await UI.setLanguage('zh-CN');

UI.Events.LANGUAGE_CHANGED fires with (previousLanguage, newLanguage). UI.getCurrentLanguage() returns the current language, and UI.getAvailableLanguages() returns the language codes that can be used.

UI.setTranslations(language, translations) ​

Add or override translations of a language. The keys are the keys of translation-<lng>.json.

javascript
UI.setTranslations('en', {
  toolbar: { toolbarGroup: { annotations: 'Markup' } },
});

UI.getLocalizedText(key) returns the translation of a key in the current language.

UI.addLanguage(language) ​

Add a language to the language list in the settings dialog.

javascript
UI.addLanguage({ code: 'ko', name: '한국어' });

UI.removeLanguage(language) ​

Remove a language from the language list.

javascript
UI.removeLanguage('fr');

UI.setLanguages(languages) ​

Replace the language list.

javascript
UI.setLanguages([
  { code: 'en', name: 'English' },
  { code: 'zh-CN', name: '简体中文' },
]);

How i18n is initialized ​

  • Each instance creates its own i18next instance, so two viewers can show different languages.
  • Language selection: the saved language of the instance, then the defaultLanguage option, then en.
  • Loading: {uiPath}locales/translation-<lng>.json is loaded when a language is first used. Translations added with setTranslations are merged with the loaded file.

Examples ​

Switch to Japanese ​

javascript
await UI.setLanguage('ja');

Add a custom language ​

javascript
UI.addLanguage({ code: 'ko', name: '한국어' });
UI.setTranslations('ko', {
  toolbar: { toolbarGroup: { annotations: '주석' } },
  /* …full translation map… */
});
await UI.setLanguage('ko');

The structure follows the i18next resource structure; see webviewer/locales/translation-en.json for the full set of keys. Keys without a translation fall back to English.