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.

namespacesRequired are not loaded for fallbackLng

See original GitHub issue

After converting one of my apps from just a react-i18next example to next-i18next, I noticed a rendering glitch in one place when a non-default language is chosen. As it turned out, I simply forgot to add one translation string for that language. The reason why the bug did not show itself before was because fallbackLng was successfully leveraged. After the switch, initialI18nStore stopped containing translation strings for the default language. When fallbackLng is manually set or when the app is in production mode, the string from a fallback language is rendered, but after a delay (following async namespace fetching).

Should the current behaviour be changed, so that partially translated non-default languages still produced a working app that does not blink right after loading?

Related lines: https://github.com/isaachinman/next-i18next/blob/fa04883f3b79d84949cd7853f94cd350a99d7ce6/src/hocs/app-with-translation.js#L88-L95

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
isaachinmancommented, Dec 29, 2018

Hi @kachkaev, happy holidays to you.

Yes, I think we should indeed be loading in the namespaces in the fallback language if it’s not the same as initialLanguage. It’s not just about fallbacks in the case of user error (failure to translate) - sometimes applications specifically want certain content to be in English (for example), even on foreign lang pages.

0reactions
kachkaevcommented, Jan 6, 2019

Hi @isaachinman! Sorry for a slow response, I’m still in the process of returning back to reality after the winter holidays 😅

I also believe that https://github.com/isaachinman/next-i18next/commit/463520acf274928df73b8e2dc709b65a2915b85c solves the issue – you got it right! Here’s an MWE: https://github.com/kachkaev/next-i18next/tree/issue-72-reproduction (the branch is on top of 0.16.0, before your fix)

Here’s is how page loading looks in prod mode (yarn build && yarn start):
issue-72

As you can see, h1 renders on the server, but when client-side rendering kicks in, the string disappears, because en is not a part of initialI18nStore. When index.json and common.json are asynchronously fetched, another client-side render fixes things. The flickering of the header may be invisible by default given that the local network is pretty fast without throttling.

Rebasing my MWE branch on top of your master following by a rebuilt of the lib solves the problem! Opening page source reveals that common and index namespaces for both de and en are now a part of nextI18nStore, so no client-side fetching and therefore re-rendering is needed. Feel free to close this issue unless you want to ask something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

requiredNamespaces not recognized after navigation · Issue #153 ...
The exact error (note component name!) You have not declared a namespacesRequired array on your page-level comp onent: Connect(LoadNamespace(MyPageComponent)).
Read more >
declaring namespacesRequired array on page-level component
You have not declared a namespacesRequired array on your page-level component: withI18nextTranslation(Error). This will cause all namespaces ...
Read more >
Fallback - i18next documentation
Doing graceful fallbacks is a core principle of i18next. This enables you to display the most accurate content possible, while not repeating content...
Read more >
next-i18next - npm
Because resources are loaded once when the server is started, any changes made to your translation JSON files in development will not be...
Read more >
i18next - OSCHINA - 中文开源技术交流社区
values(localesHash) .reduce( (previous, current) => previous.concat(current), [] ) if (locales === undefined) { console.error('This country is not in service.
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