-1

What's the best approach in using VUE i18n for a long text paragraph? I know that I can use backticks (``) and even preserve carriage return but is this the way to go? Or is better to conditionally load different JSON files according to the locale settings?

EanX
  • 475
  • 4
  • 21

1 Answers1

1

You can use the following in your template to have some content i18n'ed: {{ $t('deeply.nested.key') }} and reference a JSON with a super long value. If your block do not require anything more than just pure text, it'll be fine. enter image description here

If you need to add some styling, a new line, some conditional rendering or anything more than just text, I'd recommend using component interpolation. It will prevent having ugly inline html/css in your JSON.

On a totally other topic, indeed, lazy loading the locales is a good idea too.

Here is a little snippet of code on how to achieve it, more details can be found on the dedicated page.

// If the language hasn't been loaded yet
return import(/* webpackChunkName: "lang-[request]" */ `@/i18n/messages/${lang}.js`).then(
  messages => {
    i18n.setLocaleMessage(lang, messages.default)
    loadedLanguages.push(lang)
    return setI18nLanguage(lang)
  }
)
kissu
  • 40,416
  • 14
  • 65
  • 133