How to use all locales from server ONLY
See original GitHub issueHi guys, Im trying to use next to load all the locales from server API and not from any local folder
in _app.tsx:
export const getInitialProps = () => ({});
in i18n.js:
module.exports = {
locales: ['en', 'de'],
defaultLocale: 'en',
pages: {
'*': ['common'],
'rgx:^/projects': ['projects'],
'rgx:^/user': ['user'],
'rgx:^/help': ['help'],
},
loadLocaleFrom: async (locale, namespace) => {
const localesUrl = `${window.location.origin}/api/i18n/${locale}/${namespace}/translations.json`;
try {
const response = await fetch(localesUrl);
if (response.status === 200) {
return await response.json();
}
console.error(`Fetching translations from ${localesUrl} failed`, response);
} catch (e) {
console.log(`Fetching translations from ${localesUrl} failed`, e);
}
return {};
},
};
What happens is, on the first load no translations are coming, after navigation in the app then all works fine.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How do I change the default locale in Ubuntu Server?
Run the command locale - it should show your current locale. Generate the locales for french: sudo locale-gen fr_FR sudo locale-gen fr_FR.UTF-8.
Read more >javascript - i18Next: use locale only for some languages and ...
With the load option set to "all", it will first check for "en-US" and if not found, it will use "en"... and the...
Read more >Table of locales - MoodleDocs
package_name lang_name locale localewin localewincharset
af_utf8 Afrikaans af_ZA.UTF‑8 Afrikaans_South Africa.1252 WINDOWS‑1252
sq_utf8 Albanian sq_AL.UTF‑8 Albanian_Albania.1250 WINDOWS‑1250
ar_utf8 Arabic ar_SA.UTF‑8 Arabic_Saudi Arabia.1256 WINDOWS‑1256
Read more >Webpack bundling causing ALL locales to get included #4025
My initial thought was that you need to just make the whole locale API async, which means that you'd use locales like.
Read more >Idea - Persist locale IN SERVER SIDE between mobile calls to ...
If you set locale with SetCurrentLocale action in server side, it sounds reasonable that the following calls from this user to servers actions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

well, I’m glad you solved it 😊
Sorry my bad… this was a very stupid error… look:
basically as you said the using
windowobject should throw this errorReferenceError: window is not definedbut because I had an error on thecatchclause… no error was to be seen…So now all works as expected! thank you for your time