Localization
The editor's chrome and runtime surfaces read user-facing copy through DocumentEditorLocalizations, backed by slang-generated, namespace-split dictionaries in packages/vyuh_document_flutter/lib/l10n/.
English (en) is compiled into the main bundle for synchronous first paint. Every additional built-in locale compiles into its own deferred Dart library (lazy: true in slang.yaml), so shipping multiple languages adds zero initial payload to main.dart.wasm on Flutter Web: a browser downloads a locale's dictionary chunk (~4–6 KB Brotli) only when that locale is selected.
Built-in locales
DocumentEditorLocalizations.supportedLocales ships five locales out of the box:
| Locale | Language code | Native display name | Digit grouping |
|---|---|---|---|
| English | en | English | 12,480 |
| Spanish | es | Español | 12.480 |
| German | de | Deutsch | 12.480 |
| Hindi | hi | हिन्दी | 12,480 |
| Japanese | ja | 日本語 | 12,480 |
1. Standard Flutter app wiring
If your app already uses flutter_localizations, install DocumentEditorLocalizations.delegate alongside Flutter's global delegates:
dart
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:vyuh_document_flutter/vyuh_document_flutter.dart';
MaterialApp(
locale: activeLocale, // e.g. Locale('es'), Locale('de'), Locale('hi'), Locale('ja')
supportedLocales: DocumentEditorLocalizations.supportedLocales,
localizationsDelegates: const [
DocumentEditorLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: MyDocumentWorkspace(),
);Lean WASM apps (without flutter_localizations)
If you want to keep flutter_localizations out of your web bundle while still switching the editor's language on the fly, wrap the app inside MaterialApp.builder with DocumentEditorLocalizations.scoped:
dart
MaterialApp(
builder: (context, child) => DocumentEditorLocalizations.scoped(
locale: activeLocale,
child: child ?? const SizedBox.shrink(),
),
home: MyDocumentWorkspace(),
);DocumentEditorLocalizations.scoped fetches the requested locale's deferred slang chunk in the background, keeps the current bundle painted until the chunk is ready (no blank flash), caches it in memory, and serves every widget and overlay dialog under MaterialApp.
When locale changes, DocumentEditorLocalizations.delegate loads that locale's deferred slang bundle once, caches it in memory, and serves subsequent switches synchronously. Any locale outside supportedLocales falls back to English without throwing a delegate mismatch assertion.
You can also preload or pass a bundle explicitly without MaterialApp:
dart
final spanish = await DocumentEditorLocalizations.load(const Locale('es'));
DocumentRuntimeEditor(
controller: controller,
configuration: DocumentEditorConfiguration(localizations: spanish),
);Or scope it to a subtree with DocumentEditorLocalizationsScope:
dart
DocumentEditorLocalizationsScope(
localizations: spanish,
child: myEditorSubtree,
)2. Live switching from the status bar
DocumentStatusBar includes an optional language picker that lets readers switch locales on the fly:
dart
DocumentStatusBar(
controller: controller,
canvas: canvasController,
zoom: zoomCapability,
locale: activeLocale,
supportedLocales: DocumentEditorLocalizations.supportedLocales,
onLocaleChanged: (next) => setState(() => activeLocale = next),
)Leave onLocaleChanged null to omit the language picker. Try it live in the playground — click the language picker in the bottom status bar (or open /?locale=es, /?locale=de, /?locale=hi, /?locale=ja).
3. Override specific strings
Replace selected product terms without subclassing or forking a locale using DocumentEditorLocalizations.delegateWithOverrides:
dart
MaterialApp(
locale: activeLocale,
supportedLocales: DocumentEditorLocalizations.supportedLocales,
localizationsDelegates: [
DocumentEditorLocalizations.delegateWithOverrides(
overrides: {
const Locale('en'): const {
'chrome.modeSuggesting': 'Track Changes',
'common.addComment': 'Add Review Note',
},
const Locale('es'): const {
'chrome.modeSuggesting': 'Control de cambios',
},
},
),
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
home: MyDocumentWorkspace(),
);Keys accept either the slang namespace path ('chrome.modeSuggesting') or the DocumentEditorLocalizations getter name ('modeSuggesting'). Omitted keys fall back automatically to the resolved built-in bundle.
4. Supply an unbundled locale at runtime
To support a locale that Vyuh Document does not ship yet (for example Catalan ca or French fr), load your own JSON map at runtime and wrap it with DocumentEditorLocalizations.fromMap:
dart
final catalanStrings = <String, String>{
'chrome.menuFile': 'Fitxer',
'chrome.menuEdit': 'Edita',
'chrome.menuView': 'Visualitza',
'chrome.modeEditing': 'Edició',
'status.wordCount': 'Recompte de paraules',
};
MaterialApp(
locale: const Locale('ca'),
supportedLocales: const [Locale('en'), Locale('ca')],
localizationsDelegates: [
DocumentEditorLocalizations.delegateFor(
(locale) => locale.languageCode == 'ca'
? DocumentEditorLocalizations.fromMap(
locale: locale,
overrides: catalanStrings,
)
: const DocumentEditorLocalizations(),
),
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
home: MyDocumentWorkspace(),
);For full control over pluralization, formatting, or custom logic, you can also subclass DocumentEditorLocalizations directly and supply it via DocumentEditorLocalizations.delegateFor.
5. Extension & plugin packages
Optional Flutter plugin packages own their own slang-generated deferred dictionaries (lazy: true), keeping plugin-specific copy out of vyuh_document_flutter:
| Package | Auto-registered contributor | Standalone delegate |
|---|---|---|
vyuh_document_katex_flutter | KatexDocumentLocalizations.contributor | KatexDocumentLocalizations.delegate |
vyuh_document_mermaid_flutter | MermaidDocumentLocalizations.contributor | MermaidDocumentLocalizations.delegate |
vyuh_document_diagram_flutter | DiagramDocumentLocalizations.contributor | DiagramDocumentLocalizations.delegate |
Automatic wiring inside DocumentEditor
When you install KatexDocumentExtension, MermaidDocumentExtension, or DiagramDocumentExtension, each extension registers its DocumentLocalizationsContributor with DocumentEditorLocalizations automatically. Host apps still install only one delegate (DocumentEditorLocalizations.delegate or DocumentEditorLocalizations.scoped(...)): switching locales loads the core editor chunk and every installed plugin's chunk in parallel on demand.
Standalone widget usage
If you mount plugin widgets such as MermaidView or DiagramEditingSurface outside DocumentEditor, install the package's standalone delegate directly:
dart
MaterialApp(
locale: activeLocale,
supportedLocales: MermaidDocumentLocalizations.supportedLocales,
localizationsDelegates: const [
MermaidDocumentLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: MermaidView(source: 'flowchart LR\n A --> B'),
);Registering custom third-party extensions
Custom document extensions can contribute their own deferred locale maps through the same seam inside register(ElementRegistry registry):
dart
DocumentEditorLocalizations.registerContributor(
DocumentLocalizationsContributor(
id: 'my_custom_document_extension',
load: (locale) async => switch (locale.languageCode) {
'es' => const {'Insert callout card': 'Insertar tarjeta destacada'},
'de' => const {'Insert callout card': 'Hinweiskarte einfügen'},
_ => const {},
},
),
);Dictionary namespaces
Translation files in packages/vyuh_document_flutter/lib/l10n/<locale>/ are split into six namespaces (with matching ui.i18n.json dictionaries in each optional Flutter plugin package):
| File | Covers |
|---|---|
common.i18n.json | Shared buttons (apply, cancel, insert), clipboard, links, comments, protection, spellcheck, table cells |
chrome.i18n.json | Rulers, zoom, interaction modes, menus, view switch, sidebars, language switcher |
status.i18n.json | Preparation overlays, drag-and-drop feedback, status bar labels, digit grouping, plurals |
settings.i18n.json | Editor settings panel sections and toggles |
properties.i18n.json | Properties panel banner, destinations, and section headers |
ui.i18n.json | Shared UI dictionary (1,000+ keys) powering tooltips, File/Edit/Insert/Format/References/Review/View menu items, ribbon controls, command palette, dialogs, search bar, standard vyuh_document_elements labels, and element Properties fields via DocumentEditorLocalizations.translate |
Adding a new built-in locale (contributors)
- Copy
lib/l10n/en/tolib/l10n/<lang>/(for exampleca/orfr/) inpackages/vyuh_document_flutterand any optional Flutter plugin package (vyuh_document_katex_flutter,vyuh_document_mermaid_flutter,vyuh_document_diagram_flutter). Partial translations are valid:slangusesfallback_strategy: base_locale, so any untranslated key falls back to English at compile time. - Regenerate the typed bundles and deferred loaders across all four packages:
sh
dart run melos run gen:l10n- Add the
Locale('<lang>')entry toDocumentEditorLocalizations.supportedLocales(and the pluginsupportedLocaleslists) and its native endonym toDocumentEditorLocalizations.localeDisplayName. - Verify with
flutter test test/document_slang_localizations_test.dartinsidepackages/vyuh_document_flutter.