Internationalization (i18n)¶
MageObsidian translates phrases in the Vue/ESM layer with the same dictionary as the rest of the storefront β Magento's native per-locale js-translation.json. You write $t('β¦') in components exactly like Magento's $t / $.mage.__, and the standard CSV β language-pack flow applies.
Translating in Components¶
The i18n plugin (obsidianI18n) is wired into every Vue island automatically β you don't register anything. In templates, use $t:
In <script setup>, use the useTranslate() composable:
%1, %2, β¦ are positional placeholders, substituted in order. An out-of-range placeholder is left untouched, so a malformed phrase never throws.
How It Works¶
- PHP publishes the runtime config on the page as
window.__MAGE_OBSIDIAN_I18N__ = { locale, dictionaryUrl }(emitted once by theI18nRuntimeblock). - The browser fetches the dictionary from
dictionaryUrlβ Magento's nativejs-translation.jsonfor the active locale β once, shared across every mounted app, held reactively so$tre-renders as soon as it resolves. - A phrase is looked up in the dictionary, falling back to the phrase itself when absent; then placeholders are interpolated.
Because the dictionary is Magento's own js-translation.json, translations come from the same CSV / language packs as the rest of the storefront β there is no parallel translation system.
Collecting Phrases¶
$t('β¦') calls written in .vue files are not visible to Magento's PHP-based phrase scanners, so MageObsidian ships a collector:
It scans the $t('β¦') phrases in the .vue sources of every compatible module and theme and merges them into that component's standard Magento dictionary, i18n/<locale>.csv. New phrases default to themselves, so they flow into js-translation.json through the native static-content deploy once translated.
| Option | Description |
|---|---|
--locale |
Locale of the CSV to write (default en_US). |
End-to-end¶
Key Notes¶
$tworks in any island component out of the box β the plugin is already installed by the island runtime.- The dictionary is Magento's native
js-translation.json; no separate i18n backend. - If the config global is absent (e.g. no islands on the page), the layer degrades to passthrough β phrases render as written.
- Always run
mage-obsidian:i18n:collectafter adding new$t('β¦')phrases so they reach the CSV and, after deploy, the dictionary.
Next Steps¶
- Vue Islands β the runtime that wires the i18n plugin.
- Vue Components β authoring components.