Multilingual static site with NUXT
See original GitHub issueVersion
nuxt-i18n: 6.13.12 nuxt: 2.14.3
PROBLEM
I am trying to generate full static generated site using Nuxt with target static
. The problem i18n gnerates lots of JS that is shipped to the browser and never used: dist/_nuxt/static/1598426386/state.js
contains transaltion JSON file __i18n
which can be pretty big (contains all possible transaltions, only a fraction is actually used on the current site) and because the site was already generated they are not used. I do not need a hot language swap. Ideally I would love to see i18n only during the generate phase and do not include any of its features for production site. Maybe this could be an inspiration
https://www.npmjs.com/package/static-i18n
Is there a way use I18N only during the generate phase and do not include it for production or alt least minimaze the __i18n.langs
size
dist/_nuxt/static/1598426386/state.js
:
window.__NUXT__ = {
staticAssetsBase: "\u002F_nuxt\u002Fstatic\u002F1598449871",
layout: "default",
error: null,
serverRendered: true,
routePath: "\u002F",
config: {},
__i18n: {
langs: {
cs: {
brand: "U Veselých",
penzion: "penzion",
.... More translations
Config
{
defaultLocale: 'cs',
vueI18nLoader: false,
vueI18n: {
fallbackLocale: 'cs',
},
locales: [
{ code: 'en', file: 'en.json', iso: 'en-US'},
{ code: 'de', file: 'de.json', iso: 'en-US'},
{ code: 'pl', file: 'pl.json', iso: 'en-US'},
{ code: 'cs', file: 'cs.json', iso: 'en-US'}
],
lazy: true,
langDir: 'assets/localization/',
seo: true,
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top GitHub Comments
Even full-static site is initializing the Vue runtime after load so if you wouldn’t have translations available somewhere, the strings would just go blank (or rather show just the keys). So it’s not possible to get rid of them entirely.
The only thing that could be considered here is whether the locales should be included in the
nuxtState
(state.js
) or only in a separate JS locale files (lang-*.js
). Including them innuxtState
means that every generated page will carry that same payload while if we don’t do that, the pages will have to do an extra request to get the locale file.For full-static (or just generated) sites, I would lean towards not having locales in the nuxtState.
As you’ve mentioned, there is
lazy.skipNuxtState
option (https://i18n.nuxtjs.org/options-reference#lazy) so closing this.