nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.71k stars 478 forks source link

Lazy-loading translations fetching both on server and client. #2815

Closed martinsjek closed 7 months ago

martinsjek commented 7 months ago

Environment

StackBlitz

Reproduction

https://stackblitz.com/edit/github-orzjqc-1mczdr?file=lang%2Fen.ts,lang%2Flv.ts,pages%2Findex.vue,nuxt.config.ts

Describe the bug

The language files en.ts and lv.ts are called both on server and client. I have two issues with this:

  1. I think the file should be called only server-side. If i would have a $fetch() inside, let's say en.ts, then the $fetch would be called twice once on a server once on a client.
  2. I think language files should be called per visit. Let's say I open only LV version of the page It should not trigger en.ts, but it does.

Additional context

No response

Logs

No response

martinsjek commented 7 months ago

I am closing this issue as everything works as expected.

Explanation:

  1. The requests are called twice, once server-side and once client-side, because messages are not transferred from server to client as it would make a huge response from the server if somebody loads 5MB worth of translations to their page.
  2. This actually calls desired locale and default locale(for fallback).