-
Notifications
You must be signed in to change notification settings - Fork 0
i18n
Jones edited this page Jun 24, 2026
·
1 revision
Mango provides built-in internationalization (i18n) support, allowing developers to localize both user interface controls and dynamic metadata.
Mango currently supports four languages:
- English (en) (Default)
- Spanish (es)
- Welsh (cy)
- French (fr)
The raw translation JSON files are stored in the src/locales directory:
The translation pipeline is handled in src/lib/core/i18n.ts. It exports the following APIs:
-
locale: A writable Svelte store containing the active locale string (e.g.'cy'). -
setLocale(value: string): Normalises and sets the active locale. It falls back to'en'if the requested locale is unsupported. -
getLocale(): Synchronously retrieves the current locale string.
-
translate(key: string, params?: Record<string, string | number>, overrideLocale?: string):- Looks up the dot-notation key (e.g.
plugins.hello.label) inside the target locale's JSON. - Formats variables matching the
{variableName}syntax.
- Looks up the dot-notation key (e.g.
-
t: A derived Svelte store providing a reactive lookup handler inside Svelte components.
<script lang="ts">
import { t } from '../core/i18n';
</script>
<div class="header">
<h2>{$t('viewer.gallery.canvasAlt', { index: 1 })}</h2>
<button>{$t('viewer.controls.close')}</button>
</div>import { translate } from '../core/i18n';
console.log(translate('warnings.pluginMissingId'));-
Create the translation file: Create a new JSON file under
src/locales/(e.g.,de.jsonfor German). Copy the keys fromen.jsonand translate the values. -
Register the file in
i18n.ts: Import the JSON and append it to the catalogue:import de from '../../locales/de.json'; const catalogue = { en, es, cy, fr, de, // Register here };
- Validation: Run translation checks to verify all translation keys are present across JSON catalogues.