@docx-editor.dev/i18n
Locale catalogs for editor controls, including right-to-left Arabic and Hebrew.
Set the interface language
Install the package as a direct dependency when you import its catalogs:
npm install @docx-editor.dev/i18nPass a catalog to i18n. This example uses Spanish controls and Spanish regional date input:
import { DocxEditor } from '@docx-editor.dev/react';
import { es } from '@docx-editor.dev/i18n';
<DocxEditor document={bytes} i18n={es} locale="es-ES" />;<script setup lang="ts">
import { DocxEditor } from '@docx-editor.dev/vue';
import { es } from '@docx-editor.dev/i18n';
defineProps<{ bytes: Uint8Array }>();
</script>
<template>
<DocxEditor :document="bytes" :i18n="es" locale="es-ES" />
</template>| Prop | Sets | Default |
|---|---|---|
i18n | Interface strings | The enclosing LocaleProvider catalog, or English |
locale | Regional date input and generated labels | en-US |
Neither setting infers the other. For date input, see form fields.
Choose a catalog
| Code | Language | Named export | Direction |
|---|---|---|---|
en | English | en | LTR |
ar | Arabic | ar | RTL |
pl | Polish | pl | LTR |
de | German | de | LTR |
es | Spanish | es | LTR |
fr | French | fr | LTR |
pt-BR | Brazilian Portuguese | ptBR | LTR |
he | Hebrew | he | RTL |
hi | Hindi | hi | LTR |
id | Indonesian | id | LTR |
ja | Japanese | ja | LTR |
ru | Russian | ru | LTR |
tr | Turkish | tr | LTR |
zh-CN | Chinese (Simplified) | zhCN | LTR |
- Hyphenated codes use camelCase exports:
ptBRandzhCN. - A named import (
import { es } from '@docx-editor.dev/i18n') suits a fixed set of locales. - A dynamic subpath import loads a locale on demand:
(await import('@docx-editor.dev/i18n/es')).default. A static subpath import bundles it.
Configure providers and imports
| API | Use |
|---|---|
i18n prop on <DocxEditor> | Sets the catalog for one packaged editor. |
LocaleProvider | Shares a catalog across editors. Composed editors need it, because DocxEditor.Root has no i18n prop. |
dir="rtl" on LocaleProvider | Mirrors the controls for a catalog without _dir. |
useTranslation() | Returns t so custom controls read the same catalog. |
This example shares a catalog and reads it in a custom control:
import { DocxEditor, LocaleProvider, useTranslation } from '@docx-editor.dev/react';
import { pl } from '@docx-editor.dev/i18n';
function BoldLabel() {
const { t } = useTranslation();
return <span>{t('formattingBar.bold')}</span>;
}
<LocaleProvider i18n={pl}>
<DocxEditor document={bytes} />
</LocaleProvider>;<script setup lang="ts">
import { DocxEditor, LocaleProvider } from '@docx-editor.dev/vue';
import { pl } from '@docx-editor.dev/i18n';
defineProps<{ bytes: Uint8Array }>();
</script>
<template>
<LocaleProvider :i18n="pl">
<DocxEditor :document="bytes" />
</LocaleProvider>
</template>For composed editors, see the React and Vue examples. For scoped overrides, see Language.
Limits
- Each catalog overrides the inherited catalog one key at a time.
- Missing and
nullkeys inherit from an outer provider. Without one, they fall back to English. - Arabic and Hebrew catalogs declare
_dir: 'rtl', and the controls mirror. Set_dir: 'rtl'in your own catalog, or passdir="rtl". See Right-to-left support. - Korean document text does not need a Korean interface catalog. See CJK text.
Next steps
- Contributing a translation: Add or fix a locale.
- i18n API reference: Every locale export.
- Language: Override strings in one scope.