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.

How to use all locales from server ONLY

See original GitHub issue

Hi 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:closed
  • Created a year ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
aralrocacommented, May 18, 2022

well, I’m glad you solved it 😊

1reaction
fs-innonovacommented, May 18, 2022

Sorry my bad… this was a very stupid error… look: image basically as you said the using window object should throw this error ReferenceError: window is not defined but because I had an error on the catch clause… no error was to be seen…

So now all works as expected! thank you for your time

Read more comments on GitHub >

github_iconTop 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 >

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