i18n support #6
-
Noob question here: could I use vue-i18n with Iles and still get it work? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Hi Enrico! An Generate a different site per localeThis is common in documentation sites. You would run the build once per language, passing the language in an environment variable or a different mean. In import { defineApp } from 'iles'
import { createI18n } from '~/logic/i18n'
export default defineApp({
enhanceApp ({ app }) {
const i18n = createI18n()
app.use(i18n)
i18n.global.locale = import.meta.env.VITE_LOCALE
},
}) Single-site with all localesAt the moment, it's a very manual process, which is why I plan to create a plugin. Currently, you would create a copy of each route per language using the import { defineConfig } from 'iles'
export default defineConfig({
pages: {
onRoutesGenerated (routes) {
const languages = ['en', 'es']
return languages.flatMap(lang =>
routes.map(route => route.path === '/' && lang === 'en' ? route : ({
...route,
name: `${lang}-${route.name}`,
path: `/${lang}${route.path}`,
meta: { ...route.meta, lang },
})),
)
},
},
}) Then, in import { defineApp } from 'iles'
import { createI18n } from '~/logic/i18n'
export default defineApp({
enhanceApp ({ app, route, router }) {
const i18n = createI18n(route)
app.use(i18n)
router.afterEach(route => { i18n.global.locale = route.meta.lang })
},
}) Global Helpers in IslandsSince islands won't have the entire app context (or translations), if you need translated content inside islands, you should pass it explicitly using props. |
Beta Was this translation helpful? Give feedback.
-
Thank you, Maximo! This is how I used
src/app.ts import { defineApp } from 'iles'
import { createI18n } from 'vue-i18n'
import en from '~/locales/en.json'
import de from '~/locales/de.json'
const messages = Object.assign({
en: en,
de: de,
})
export default defineApp({
enhanceApp ({ app }) {
const i18n = createI18n({
locale: import.meta.env.VITE_LOCALE,
messages: messages,
})
app.use(i18n)
},
}) src/locales/en.json
src/locales/de.json
src/HelloWorld.vue
And running multiple language-specific builds:
Hope this helps somebody down the road. Cheers! |
Beta Was this translation helpful? Give feedback.
-
I am using Do you know how to get aruond this? Thanks! |
Beta Was this translation helpful? Give feedback.
Hi Enrico!
An
@islands/i18n
plugin is in the roadmap. In the meantime:Generate a different site per locale
This is common in documentation sites.
You would run the build once per language, passing the language in an environment variable or a different mean. In
src/app.ts
:Single-site with all locales
At the moment, it's a very manual process, which is why I plan to create a plugin.
Currently, you would create a copy of each route per language using the
pa…