Localization
The viewer's UI strings resolve through the shared pptx.* dictionary (English built in). Svelte has no blessed i18n runtime, so this binding ships a small, dependency-free translation layer under the pptx-svelte-viewer/i18n entry point: dictionary lookup by locale with English fallback, interpolation, and a humanised fallback for missing keys.
Registering a locale
Register dictionaries (or override individual strings) with registerTranslations, then set the locale prop:
// e.g. in your app entry, before the viewer mounts
import { registerTranslations } from 'pptx-svelte-viewer/i18n';
registerTranslations('fr', {
'pptx.statusBar.slideOf': 'Diapositive {{current}} sur {{total}}',
'pptx.toolbar.next': 'Suivant',
// ...any subset; unset keys fall back to English
});<PowerPointViewer source={bytes} locale="fr" />Later registrations for the same locale are merged over earlier ones, so hosts can layer a full dictionary first and override individual keys afterwards. Register dictionaries before mounting the viewer so the labels are available on first render.
Typed dictionaries
TranslationDictionary is a plain Record<string, string>. For compile-time key checking, annotate your dictionary with the exported TranslationKey union:
import type { TranslationKey } from 'pptx-svelte-viewer/i18n';
const fr: Partial<Record<TranslationKey, string>> = {
'pptx.statusBar.slideOf': 'Diapositive {{current}} sur {{total}}',
};
registerTranslations('fr', fr);The Svelte demo registers complete French, Spanish, and German reference dictionaries through this same API.
The fallback chain
translate resolves a key in this order:
- The exact locale's dictionary (
fr-CA) - The base language's dictionary (
fr) - The built-in English dictionary (
translationsEn) - A humanised label derived from the key (
keyToLabel), so missing keys never render as raw dotted paths
Interpolation
Messages use the shared placeholder convention; parameters are passed as the second argument to the translator:
import { translate } from 'pptx-svelte-viewer/i18n';
translate('en', 'pptx.statusBar.slideOf', { current: 2, total: 10 });
// "Slide 2 of 10"Unknown placeholders are left verbatim.
The built-in language picker
File > Options > Language offers the user a locale choice at runtime, driven by three props (see Component Props):
defaultLocale: initial selection; falls back to thelocalStorage-persisted choice, then thelocaleprop.availableLocales: the choices offered (LocaleCatalogEntry[]). Defaults to every locale registered viaregisterTranslations, labelled from the sharedLOCALE_CATALOG(en,fr,es,deship with labels; other codes get their code as label).onLocaleChange: fired with the selected code. Supplying it hands persistence to the host; without it the choice is written tolocalStorageautomatically.
interface LocaleCatalogEntry {
/** BCP-47-ish locale code, e.g. 'en', 'fr'. */
code: string;
/** English display name. */
label: string;
/** The locale's own name for itself, e.g. 'Français'. */
nativeLabel: string;
}Picking is not registering
The picker only switches which registered dictionary is read. Registering the dictionary itself is a separate step (registerTranslations); a picked locale with no dictionary falls back to English.
Helper reference
All from pptx-svelte-viewer/i18n:
| Export | Kind | Purpose |
|---|---|---|
registerTranslations | function | (locale, dictionary) => void; merges over any existing dictionary for that locale. |
getRegisteredLocales | function | () => string[]; 'en' plus everything registered. |
translate | function | (locale, key, params?) => string; full fallback chain. |
createTranslator | function | (getLocale) => Translator; a translator bound to a lazily-read locale. |
interpolate | function | (message, params?) => string; substitution only. |
translationsEn | const | The complete shared English dictionary. |
LOCALE_CATALOG | const | Built-in locale labels (en, fr, es, de). |
keyToLabel | function | Humanises a pptx.* key; the last-resort fallback. |
TranslationDictionary, Translator, TranslationKey, LocaleCatalogEntry | type | The types used above. |
registerTranslations, TranslationDictionary, and Translator are also re-exported from the package root for convenience.