@trupdf/i18n
Locale runtime + 31 locale bundles. Lazy-loaded bundles, RTL detection, host-overridable resource bundles.
Exports
import {
SUPPORTED_LOCALES,
LOCALE_LABELS,
isRTL,
changeLanguage,
getTruPDFI18n,
I18nProvider,
LanguageSwitcher,
useTranslation,
} from '@trupdf/viewer';SUPPORTED_LOCALES
const SUPPORTED_LOCALES: ReadonlyArray<Locale>;31 codes: en es fr de it pt pt-BR nl sv no da fi pl cs hu tr ru uk el ar he fa hi bn th vi id zh-CN zh-TW ja ko. RTL: ar, he, fa
(the RTL_LOCALES set in @trupdf/i18n). See
Customization → i18n.
Initial language
Pass the language prop to DocViewer (default 'en'):
<DocViewer source="/file.pdf" language="de" />changeLanguage
await changeLanguage('fr'); // lazy-loads the bundle, then switchesgetTruPDFI18n
Singleton runtime instance. Use it to add custom resources or override defaults:
const i18n = getTruPDFI18n();
i18n.addResourceBundle(
'en',
'trupdf',
{
toolbar: { search: 'Find in document' },
},
true,
true,
);I18nProvider
<I18nProvider language="en">{children}</I18nProvider>Wraps the runtime provider around children. Skip if you mount the
viewer through DocViewer — it provides its own.
LanguageSwitcher
<LanguageSwitcher
className="my-class"
onChange={(locale) => analytics.track('locale-changed', { locale })}
/>Native <select> with LOCALE_LABELS text content.
useTranslation
Hook pre-scoped to the trupdf namespace:
const { t, i18n } = useTranslation();
t('toolbar.print');isRTL
isRTL('ar'); // trueUse to set dir="rtl" on host wrappers when needed.
Source strings
All English source strings live under the trupdf namespace
(exported as TRUPDF_NS) in packages/i18n/src/locales/en.json.
Other locales are translations of that file. Missing keys fall back to
English.