question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multilingual static site with NUXT

See original GitHub issue

Version

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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
rchlcommented, Aug 26, 2020

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 in nuxtState 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.

0reactions
rchlcommented, Mar 30, 2022

As you’ve mentioned, there is lazy.skipNuxtState option (https://i18n.nuxtjs.org/options-reference#lazy) so closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to build a Jamstack multi-language blog with Nuxt.js
In this tutorial you'll learn how to build a Jamstack multilanguage blog using Nuxt.js, a powerful Vue framework that supports SPA, SSR and ......
Read more >
The complete guide to building a multilanguage ... - Storyblok
This the ultimate Nuxt.js guide for beginners and professionals who want to build a full-blown multilanguage website using Nuxt, TailwindCSS & Storyblok.
Read more >
Multilingual static site with NUXT · Issue #866 - GitHub
I am trying to generate full static generated site using Nuxt with target static . The problem i18n gnerates lots of JS that...
Read more >
Building a multilingual blog using Nuxt and Markdown
... a multilingual serverless blog with Nuxt, the reason why I chose it, differences between building a webapp blog and a static one, ......
Read more >
Nuxt generate with vuex and multi-language site
So first of all, on generate saves the results of the nuxtServerInit() of the store and the asyncData() and fetch() of the layout...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found