File ViewerDocs
Skip to Content
File ViewerDocs
Documentation
Guide9 min read

Interface languages

Seven offline UI languages, locale negotiation, live updates and custom translations across File Viewer components.

简体中文

The shared core bundles zh-CN, en-US, ja-JP, zh-TW, zh-HK, de-DE and ru-RU synchronously. UI translations need no network request. Vanilla, Web Component, Vue 3, Vue 2.6/2.7, React, React Legacy, Svelte and jQuery use the same resources in light and Full packages. Documentation and the website retain English and Simplified Chinese routes.

Start with Vanilla or Web Component

import { mountViewer } from '@file-viewer/web-full'
import { FILE_VIEWER_LOCALE_OPTIONS } from '@file-viewer/core'

const viewer = mountViewer(document.getElementById('preview')!, {
  url: '/files/report.pdf',
  options: { locale: 'zh-TW' }
})
// Use each option's value and native label in your language selector.
console.table(FILE_VIEWER_LOCALE_OPTIONS)
await viewer.update({ options: { locale: 'ru-RU' } })
<flyfish-file-viewer src="/files/report.pdf" locale="ja-JP"></flyfish-file-viewer>

Set element.locale or element.options.locale through the existing element API. Framework components update their options prop; Svelte actions use action.update, and jQuery uses .fileViewer('update', { options: { locale } }). The current document, page, zoom, scroll, search and worksheet remain in place. A language update does not download or parse the source again. Renderer configuration changes still follow their usual reload rules.

Negotiation and isolation

InputDictionary
zh, zh-CN, zh-SG, zh-Hans-*zh-CN
zh-TW, zh-Hant, other non-HK/MO zh-Hant-*zh-TW
zh-HK, zh-MO, zh-Hant-HK, zh-Hant-MOzh-HK
English, Japanese, German or Russian regional variantsMatching bundled language

Explicit script wins: zh-Hans-HK uses Simplified Chinese and zh-Hant-CN uses Taiwan Traditional Chinese. Case and underscores are accepted. Invalid or unsupported explicit tags fall back to English.

auto checks navigator.languages in order, then navigator.language; unsupported browser preferences fall back to English. With no browser information, the historical Simplified Chinese default remains. Browser languagechange events affect automatic instances only. Use an explicit locale for matching SSR and hydration output.

Each instance owns its language context. Nested archive entries and mail attachments inherit it. Components do not access host preference storage or change the host document's language. Authored content, its language/direction/fonts, filenames and raw metadata retain their original meaning. Demo preferences use URL → saved choice → browser priority, tolerate unavailable storage and preserve the selected file.

Select dictionaries at build time

The default entrypoints keep all seven languages available synchronously. To ship only your chosen dictionaries, enable the file-viewer-custom-locales package condition in the application bundler. It applies consistently to Core's root, browser, headless, export and print-mask entrypoints, including imports made by framework components and renderers. The asset resolver remains the same translation-free module.

For Vite versions exposing defaultClientConditions:

import { defineConfig, defaultClientConditions } from 'vite'

export default defineConfig({
  resolve: { conditions: ['file-viewer-custom-locales', ...defaultClientConditions] }
})

For esbuild, add conditions: ['file-viewer-custom-locales']. For webpack 5, prepend the condition to resolve.conditionNames, retaining the defaults with '...'. These settings affect the whole dependency graph; importing a custom Core entry only in your application while leaving framework imports on the default entry still includes the default dictionaries.

Register the dictionaries your application uses before mounting viewers:

import { registerFileViewerLocale } from '@file-viewer/core'
import enUS from '@file-viewer/core/locales/en-US'

const unregister = registerFileViewerLocale('en-US', enUS)
// Existing component options are unchanged:
const options = { locale: 'en-US', messages: applicationMessages }
// Call unregister() only when this application no longer owns the registration.

Every locale subpath contains its complete maintained messages, feature-domain messages and plural forms. Importing one dictionary does not register it or import the other languages. A language picker can load a self-hosted bundle chunk with await import('@file-viewer/core/locales/de-DE') and then register its default export. Live viewers update their bound UI without reloading the document. Registrations can be disposed in any order; the previous live registration or default copy is restored.

Registrations belong to the application; per-viewer wording remains in options.messages. For SSR, use the same condition and registrations on the server and client before rendering. A Node server with external Core imports can use --conditions=file-viewer-custom-locales.

An unregistered locale uses the registered English dictionary. options.messages and options.i18n.messages keep their existing higher priority. If neither English nor custom copy provides a key, the key is shown without throwing. Register English as a fallback, or provide complete application copy. Replacing messages at runtime alone does not change the bundle graph; the build condition is what excludes unused dictionaries.

Older bundlers can use exact aliases for every Core entry they consume. Resolve the Core package directory with path.dirname(require.resolve('@file-viewer/core/package.json')), then map @file-viewer/core$ to dist/custom-locales.js, and /browser$, /headless$, /export$, /print-mask$ to the corresponding dist/custom-locales-*.js files in that same package. Keep /assets unchanged. Do not mix these with default Core entrypoints. The default legacy entrypoints and shims continue to work without any configuration changes.

This is an ESM application build option. Prebuilt Full IIFE/AMD bundles retain their offline, all-language defaults; an application's resolver cannot remove code already included in those bundles.

Override copy and extend renderers

options.i18n.locale and options.i18n.messages take priority over their top-level counterparts. Message keys are stable. A string dictionary or callback can override any official message; returning undefined uses built-in copy. {param} interpolation remains supported. Callbacks receive original numeric values and own their formatting.

const options = {
  locale: 'de-DE',
  i18n: { messages: { 'toolbar.download': 'Datei speichern' } }
}

Custom renderers can use the optional FileRenderContext.i18n for translation, number/date/byte formatting and change subscriptions. Prefer createFileViewerTranslator(context.i18n || context.options) so subscriptions also work in separately bundled IIFE renderers. t.text, t.attr and t.bind mark UI explicitly; never translate document content by matching DOM strings. Dispose subscriptions when the renderer is destroyed.

Call t.release(root) before permanently replacing a bound UI subtree, such as a rebuilt navigation list. It releases that subtree's subscriptions while leaving the language context active; the same nodes can be bound again later. Keep bindings on cached nodes that will be reused. Renderer-scope destruction releases the remaining subscriptions.

Counts use raw numbers with Intl.PluralRules and CLDR categories. Offline fallback rules cover missing Intl support. File sizes use explicit binary units (B, KiB, MiB, GiB, TiB). When localized date formatting is unavailable, dates fall back to unambiguous ISO strings.

Boundaries and translation review

Browser print dialogs, file pickers and native media controls follow the browser or operating system language. Third-party document content and original parser diagnostics remain available for diagnosis; UI translation does not change signature validity, support level or licensing. Runtime resources must remain self-hosted.

The new and revised translations have technical coverage checks and terminology review. Independent native-speaker review is pending for all seven languages and is tracked in the source inventory docs/maintenance/i18n-review.md. Run pnpm test:i18n for dictionary, interpolation, negotiation, isolation and plural checks, and node test/i18n.browser.mjs after building the affected packages for native framework runtime checks. New languages extend the registry and resources and use the same gates.

On this page