Localize the Editor UI

Show SuperDoc's built-in UI in the reader's language, and replace any built-in label with your own text.

Set locale to show SuperDoc's built-in UI in the reader's language. Use translations to replace any built-in label with your own text, per language.

The same document, opened with locale: 'en':

The Editor in English: a context menu with Cut, Copy, and Insert link, a comment, and a review card that reads Replaced "30" with "60".

And with locale: 'pt-BR':

The same Editor in Brazilian Portuguese: the context menu reads Recortar, Copiar, and Inserir Link, the comment timestamp reads 24 de nov., and the review card reads Substituído: "30" por "60". The document text and the comment stay as written.

locale changes SuperDoc's interface: toolbar labels, menus, dialogs, comment and review cards, and timestamps. It never changes text that is already in the document. Each reader picks their own language, even in the same live document.

Quick start

new SuperDoc({ selector: '#editor', document: '/sample.docx', locale: navigator.languages });

SuperDoc uses the first language in the reader's list that it has a pack for (see Supported languages) or that you add yourself. If none match, it shows English.

Set the language

Pass a language tag when you create the Editor:

new SuperDoc({ selector: '#editor', document: '/sample.docx', locale: 'pt-BR' });

locale accepts one BCP 47 language tag or a list of them in order of preference, the same shape as the locales argument of Intl. It defaults to 'en'. Invalid tags are skipped; they never throw.

When locale is set, SuperDoc puts the chosen language in the lang attribute of each built-in UI surface, so screen readers pronounce its labels in that language. Text that comes from the document or from other people, such as comment bodies, author names, tracked-change excerpts, and custom style names, gets lang="" (unknown). Without locale, SuperDoc adds no lang attribute.

Choose the language

Every source of a reader's language produces a tag. Pass that tag, or a list of them, to locale.

The browser

navigator.languages lists the browser's languages in order of preference. Pass it directly:

new SuperDoc({ selector: '#editor', document: '/sample.docx', locale: navigator.languages });

SuperDoc uses the first tag in the list that it has a language pack for.

Clerk

Clerk does not store a UI language on its User object. Keep the language your application saves for the user in user metadata, for example publicMetadata.language, and fall back to the browser.

Read the value on the server, where it is current, and pass it to the page:

import { currentUser } from '@clerk/nextjs/server';

const user = await currentUser();
const saved = user?.publicMetadata.language;
const locale = typeof saved === 'string' ? saved : undefined;

language is a key your application chooses. Set it from your backend with updateUserMetadata(). In the browser, useUser() keeps the metadata from when the session loaded, so call await user.reload() after you change the value.

If you also translate Clerk's own components with @clerk/localizations, pass enUS explicitly when the reader switches back to English.

next-intl

import { useLocale } from 'next-intl';

const locale = useLocale();

i18next and react-i18next

import { useTranslation } from 'react-i18next';

const { i18n } = useTranslation();
const locale = i18n.language;

Without React, read i18next.language.

vue-i18n

import { useI18n } from 'vue-i18n';

const { locale } = useI18n();

Pass locale.value when you create the Editor.

The server

On the server, read the request's Accept-Language header and send the tags to the page:

const locale = (request.headers.get('accept-language') ?? '')
  .split(',')
  .map((entry) => entry.split(';')[0].trim())
  .filter(Boolean);

This keeps the header's order and ignores its q weights. Browsers list languages from most to least preferred, so the order is usually enough. SuperDoc skips entries that are not language tags, such as *.

Replace built-in text

Set translations to replace built-in labels. The outer keys are the languages SuperDoc ships: en, pt-BR and es. Any other language tag works too; see Add a language SuperDoc doesn't ship. The inner keys are flat and dotted, such as 'toolbar.bold' or 'comments.inputPlaceholder':

import { SuperDoc, type SuperDocTranslations } from 'superdoc';
import 'superdoc/style.css';

const translations = {
  en: { 'toolbar.search': 'Find in contract' },
  'pt-BR': { 'toolbar.search': 'Buscar no contrato' },
} satisfies SuperDocTranslations;

const superdoc = new SuperDoc({
  selector: '#editor',
  document: '/sample.docx',
  locale: navigator.languages,
  translations,
});

window.addEventListener('beforeunload', () => superdoc.destroy());

SuperDoc applies the entry for the language it chose: a reader with locale: 'pt-PT' gets the pt-BR pack and the pt-BR entry. Without locale, SuperDoc uses translations.en. If the pt-BR pack cannot load, SuperDoc shows English and applies translations.en.

translations is typed as SuperDocTranslations, exported from superdoc and @superdoc/react. Your editor autocompletes the keys, and a misspelled key fails type checking. At runtime, SuperDoc ignores an entry whose outer key is not a valid language tag and logs a warning. An entry for a language SuperDoc does not ship adds that language; see Add a language SuperDoc doesn't ship.

A value that uses a {placeholder} the English text does not have, such as {nome} where English has {name}, logs a warning: SuperDoc never fills it, so it shows as written.

Labels with a count

Some labels include a number, such as comments.moreReplies ("3 more replies") and the tracked-change labels for list items. Their values use ICU plural syntax, so each language chooses the right word form for the count:

const translations = {
  'pt-BR': {
    'comments.moreReplies': '{count, plural, =0 {Sem respostas} one {Mais # resposta} other {Mais # respostas}}',
  },
} satisfies SuperDocTranslations;
  • {count, plural, ...} lists one form per plural category: zero, one, two, few, many, and other. The browser's Intl.PluralRules picks the category with the rules of the language the text is written in: a label that falls back to English uses English rules. Every plural needs an other form. A form the language never uses, such as few in Portuguese, logs a warning and is kept.
  • =0, =1, =1.5, and other =N forms match one exact number and take precedence over the category.
  • # is the count, formatted for the language: 1.000 in Portuguese. Inside a form, # always means the count.
  • A form can contain other {placeholders}, such as {name}.
  • Apostrophes are plain text; SuperDoc does not use ICU's apostrophe quoting. Braces that do not start a placeholder, such as {INTERNAL USE}, are also plain text; inside a form, open and close them in pairs.

SuperDoc supports plural only, not select, selectordinal, or number and date formats. If a translations value is not valid plural syntax, SuperDoc ignores it, logs a warning, and shows the pack's text.

Add a language SuperDoc doesn't ship

Give translations an entry for any other language, and locale can choose it like a pack SuperDoc ships:

new SuperDoc({
  selector: '#editor',
  document: '/sample.docx',
  locale: 'fr-CA',
  translations: {
    fr: {
      'toolbar.bold': 'Gras',
      'comments.moreReplies': '{count, plural, one {# autre réponse} other {# autres réponses}}',
    },
  },
});
  • locale matches your entry the same way it matches a pack: fr-CA uses a fr entry. Dates and numbers follow the full tag, fr-CA.
  • A label your entry does not translate shows the text SuperDoc would show for that tag without your entry: the pack for the same language, with its own translations entry, or English when SuperDoc ships none. A pt-PT entry falls back to Brazilian Portuguese; a fr entry falls back to English, including your translations.en values.
  • Each label your entry is missing logs one warning, the first time SuperDoc shows it.
  • Plural labels use the rules of your language: {count, plural, one {...} other {...}} picks French forms for fr, where 0 is one. See Labels with a count.
  • In a list such as locale: ['fr', 'pt-BR'], the first language with an entry or a pack wins, even if your fr entry has one label. Missing labels then fall back to English, not to the next language in the list.
  • The interface's lang attribute is your tag, so screen readers read every label in that language, including labels that fell back to English. Translate every label your interface shows to avoid mixed-language text.

Interface strings lists every key with its English text and placeholders. The package also ships them as superdoc/locales/en.json, a flat JSON file you can load into a translation tool.

SuperDoc does not review or test languages it does not ship: their wording, Word terms and plural forms are yours. To add a language for everyone, contribute it.

Use your own translation files

If your application already translates its UI, feed SuperDoc's labels from the same files. Build each language's labels with satisfies, so TypeScript checks every key:

import type { SuperDocTranslations } from 'superdoc';

type Language = 'en' | 'pt-BR';
type Translate = (language: Language, key: string) => string;

export function superdocTranslations(translate: Translate): SuperDocTranslations {
  const labels = (language: Language) =>
    ({
      'comments.inputPlaceholder': translate(language, 'editor.addComment'),
      'toolbar.search': translate(language, 'editor.find'),
    }) satisfies SuperDocTranslations[Language];
  return { en: labels('en'), 'pt-BR': labels('pt-BR') };
}

With i18next, pass (language, key) => i18next.getFixedT(language)(key).

TypeScript does not check the keys of a JSON import against SuperDocTranslations, so a misspelled key in a JSON file is silently ignored. If your translations come from a translation tool as JSON, compare their keys with superdoc/locales/en.json; see Use a translation tool.

When keys change

The keys are part of SuperDoc's public API. Within a major version, SuperDoc only adds keys. If a key is renamed, the old name keeps working until the next major version, and SuperDoc logs a warning that names the new key. Keys are removed only in a major version. To find the keys a version added, compare its en.json with the previous version's; see Find keys a new version added.

Which value wins

For each label, SuperDoc uses the first value that is set:

Four sources checked in order: the surface option, such as ui.toolbar.strings; translations for the chosen language; the language pack chosen from locale; and English.

  1. The surface's own option, such as ui.toolbar.strings, ui.toolbar.texts, or ui.search.strings, for the text that option controls.
  2. translations for the chosen language.
  3. The language pack for locale.
  4. English.

A surface option covers only the text it controls. For most toolbar buttons, such as Bold, ui.toolbar.strings and ui.toolbar.texts set only the tooltip, and the accessible name still comes from translations or the pack; to change both for Bold, set toolbar.bold in translations. The Watermark, Page number, and Comments layout buttons use the toolbar text for both, so a ui.toolbar.strings value for them also wins for their accessible name.

Existing per-surface options keep working unchanged. Use translations when you want one place for labels across surfaces. The per-surface options use different keys for the same text: ui.toolbar.strings['font-family'] and translations.en['toolbar.fontFamily'] set the same tooltip. The Toolbar and Search pages list how their keys map.

A watermark preset inserts the text its button shows, so a translations value for watermark.presetDraft, watermark.presetConfidential, or watermark.presetDoNotCopy also changes the text the preset inserts. See Watermarks.

Dates and numbers

Comment timestamps and numbers in the built-in UI are formatted with Intl for the chosen language. With 'en' they keep SuperDoc's existing English format.

Collaboration

The language belongs to each reader, not to the document. In a collaboration room, each person can open the same document with their own locale: one reviewer sees the toolbar in English while another sees it in Portuguese. Each reviewer sees tracked-change labels in their own language.

SuperDoc never stores locale in the DOCX and never shares it with other people in the room. Comment text, author names, and tracked changes appear as each author wrote them.

What is not translated

locale changes SuperDoc's interface, not the document. These stay exactly as the DOCX stores them:

  • Text already in the document, including watermark text inserted earlier, in any language.
  • Content-control placeholder text.
  • Field results, such as page numbers, dates, and cross-references.

Watermark presets insert their text in the language of the current locale, as Word inserts them in its editing language. Once inserted, the text is document content.

The document's own language is a separate setting. Word stores the language of each run of text in the DOCX (w:lang). proofing.defaultLanguage is the language SuperDoc passes to your proofing provider for text without one. locale changes neither.

React and Vue

The React and Vue wrappers accept locale and translations as props. They compare both by content, so an inline object with the same entries neither restarts the Editor nor warns; a change to its entries applies on the next mount.

src/main.ts
import { SuperDoc, type SuperDocTranslations } from 'superdoc';
import 'superdoc/style.css';

const translations = {
  en: { 'toolbar.search': 'Find in contract' },
  'pt-BR': { 'toolbar.search': 'Buscar no contrato' },
} satisfies SuperDocTranslations;

const superdoc = new SuperDoc({
  selector: '#editor',
  document: '/sample.docx',
  locale: navigator.languages,
  translations,
});

window.addEventListener('beforeunload', () => superdoc.destroy());

In Vue:

<script setup lang="ts">
import { SuperDocEditor } from '@superdoc/vue';
import '@superdoc/vue/style.css';
import type { SuperDocTranslations } from 'superdoc';

defineProps<{ locale: string }>();

const translations = {
  en: { 'toolbar.search': 'Find in contract' },
  'pt-BR': { 'toolbar.search': 'Buscar no contrato' },
} satisfies SuperDocTranslations;
</script>

<template>
  <SuperDocEditor document="/sample.docx" :locale="locale" :translations="translations" />
</template>

Change the language

SuperDoc reads locale and translations once, when the Editor is created. There is no method to change them on a running Editor.

In React and Vue, a later change to either prop keeps the open Editor and its unsaved edits, logs a warning, and applies the next time the component mounts.

To switch right away, export the document first, then open the exported copy in a new Editor with the new locale. If you remount without exporting, unsaved edits are lost. Reloading the page also applies the new language, after you have saved the document.

  • In React, change the component's key to remount it with the exported file, as the React example above does.
  • In Vanilla, export, call destroy(), and create a new SuperDoc:
import { SuperDoc } from 'superdoc';
import 'superdoc/style.css';

const open = (locale: string | readonly string[], document: string | Blob) =>
  new SuperDoc({ selector: '#editor', document, locale });

let superdoc = open(navigator.languages, '/sample.docx');

export async function switchLanguage(locale: string): Promise<void> {
  const current = await superdoc.export({ exportType: ['docx'], triggerDownload: false });
  if (!(current instanceof Blob)) throw new Error('SuperDoc did not return a DOCX file.');
  superdoc.destroy();
  superdoc = open(locale, current);
}

The localization example switches languages this way, and its edits survive the switch.

Supported languages

LanguagePackUsed for
Englishenen and any en-* tag; the fallback for all
Portuguese (Brazil)pt-BRpt-BR, pt, pt-PT, and any other pt-* tag
Spanisheses, es-ES, es-MX, es-419, and any other es-* tag

Language packs ship inside the superdoc package. There is nothing extra to install or load.

SuperDoc matches each tag in locale, in order:

  1. A pack for the exact tag, such as pt-BR.
  2. A pack for the tag without its region, keeping the script: zh-Hant-TW matches zh-Hant.
  3. A pack for the base language: pt-PT matches pt.

A translations entry for a language SuperDoc does not ship counts as a pack for this matching. If no pack matches a tag, SuperDoc tries the next one. If none match, it uses English.

If a pack has no text for a label, SuperDoc shows the English text for that label.

Coverage

A sketch of the Editor that numbers each surface that follows locale: toolbar, popups, search, context menu, comments, tracked-change labels, dialogs, and header and footer labels.

AreaFollows locale
Toolbar, its dropdowns, and the style listYes
Link, page-number, and AI writer popupsYes
Watermark dialog and presetsYes
Context menu and its panelsYes
Comments, the comments list, and comment timestampsYes
Search and replaceYes
Table, bookmark, and cross-reference dialogsYes
Loading screen and header and footer labelsYes
Tracked-change labels in review cards and listsYes
Accessible names of links, text boxes, and line breaksYes

Built-in style names follow locale, as Word shows them: heading 1 appears as Título 1 in Portuguese and Spanish. Custom style names stay as the document stores them.

Spanish uses the terms of Word's international Spanish (Spain) interface, the Spanish Office ships first.

Contribute a language

Each language is a set of message files, one per area. English, the source for every language, lives in shared/common/ui-strings/<area>.ts. A translation lives in packages/superdoc/src/core/i18n/messages/<language>/<area>.ts. To add a language:

  1. Copy the pt-BR folder and name it after the language tag, such as fr or es-MX.
  2. Translate each value with the terms Microsoft Word uses in that language. Keep {placeholders} such as {name} unchanged. For a {count, plural, ...} value, write a form for every plural category the language uses for whole numbers, such as one, few, and many in Russian. List the Word terms you used, and where Word shows them, in the folder's GLOSSARY.md.
  3. Register the folder in packages/superdoc/src/core/i18n/messages/index.ts.
  4. Run the package tests. They check that the folder and its index.ts cover every English area, that every key is translated, that placeholders match, and that each plural has the language's forms. The string inventory records every key in each language for review.

Read the contributing guide before you open a pull request.

On this page