Vue/Nuxt live editing
Live editing on Vue and Nuxt lets you click any text in your running app and edit it in a Dialecto sidebar while
vite or nuxt dev runs. It works with vue-i18n 9, 10 or 11. Nothing reaches a production build.
Install
npm install --save-dev @dialecto/vue
Setup
Vue with Vite
// vite.config.js
import vue from '@vitejs/plugin-vue'
import dialectoVue from '@dialecto/vue'
export default {
plugins: [dialectoVue({ catalogs: ['src/locales'] }), vue()],
}
List dialectoVue() before @intlify/unplugin-vue-i18n. It marks the locale files in Vite’s load hook,
before that plugin compiles them.
Nuxt
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@dialecto/vue/nuxt', '@nuxtjs/i18n'],
})
List the module before @nuxtjs/i18n. In nuxt dev it turns off i18n.experimental.optimizeMessageBundling,
which reads locale text in Nitro where nothing can mark it. Listed after, that setting comes too late, and the
console and npx @dialecto/vue doctor say so. nuxt build, generate and start are untouched.
The module finds i18n/locales or locales itself. For another folder, pass
dialecto: { catalogs: [...] } in nuxt.config.
Supported combinations:
| Nuxt | @nuxtjs/i18n |
|---|---|
| 3.21 | 8 or 9 |
| 4.0 | 9 |
| 4.6 | 10 |
Nuxt 4.6.1 with @nuxtjs/i18n 9 fails with or without Dialecto.
Editable text
Nested keys, | plural forms and @: links work. While the dev server runs, an edit shows in place exactly as
vue-i18n renders it with the page’s own values:
- a plain
{name}message; - a plural, in the form your plural rule and count choose;
- a
@:link and a@.upper:modifier; - a list argument,
{0}and{1}.
A draft vue-i18n cannot compile is not shown, and the sidebar offers Reload page for it. It offers the same
for a message whose values are not plain text, such as an object or a component slot in <i18n-t>, and for an
app that sets postTranslation.
Keys ending .url, .path, .href, .slug or _format are never marked.
Settings
Each option is also a DIALECTO_* variable, and an option wins over its variable.
| Option | Meaning |
|---|---|
url |
The Dialecto to use. |
project |
The project to edit. |
catalogs |
A folder or a list, as <locale>.json or <locale>/<ns>.json. Default src/locales. |
sourceLocale |
The language the source catalog is written in. |
keySeparator |
Default .. Use false for flat files. |
skipKeys |
Keys to leave unmarked: an exact key, prefix.* or a regular expression. |
saveToFiles |
Save to files, with DIALECTO_SCAN_TOKEN. |
enabled |
enabled: false or DIALECTO_IN_CONTEXT=off turns the add-on off. |
Pull requests
Your edits are saved in Dialecto as drafts on your project. The pull request is opened from the sidebar, and
your team reviews and merges it the usual way. Requests to /__dialecto/* need the loopback peer, the page’s
own origin and a per-session token.