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.

Didn't work with defaultLanguage different than en?

See original GitHub issue

server.js

app.prepare().then(() => {
    const server = express();

    if (!dev) {
        server.use(compression({threshold: 0}));
    }

    nextI18NextMiddleware(app, server);
...

i18n.js

module.exports = new NextI18Next({
  defaultLanguage: 'mn',
  otherLanguages: ['en'],
});

My App starts with en not mn

Issue Analytics

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

github_iconTop GitHub Comments

12reactions
ahmedengucommented, Oct 11, 2019

I was able to resolve this issue by removing ‘header’ from detectors by adding the following to my config to override the default detectors:

detection: {
    lookupCookie: 'next-i18next',
    order: ['cookie', 'querystring', 'localStorage', 'path', 'subdomain'],
    caches: ['cookie'],
  },

so the set up would be:

import NextI18Next from 'next-i18next'

const NextI18NextInstance = new NextI18Next({
  defaultLanguage: 'ar',
  otherLanguages: ['de'],
  detection: {
    lookupCookie: 'next-i18next',
    order: ['cookie', 'querystring', 'localStorage', 'path', 'subdomain'],
    caches: ['cookie'],
  },
})

export default NextI18NextInstance

/* Optionally, export class methods as named exports */
export const {
  appWithTranslation,
  withTranslation,
} = NextI18NextInstance

the header detector check the request headers for accept-language which is en in most cases

7reactions
elyash14commented, Aug 8, 2020

Hello everyone. but I had this problem and when I changed my default language to something like “fa” in the config, nothing happened and the “en” json file was loaded. I didn’t have any custom server like server.js and after some search and playing with NextI18Next configs, set serverLanguageDetection option to false and everything worked properly. new NextI18Next({ defaultLanguage: 'fa', otherLanguages: ['en'], defaultNS: 'agro', localePath: path.resolve('./public/locales'), debug: true, browserLanguageDetection: true, serverLanguageDetection: false, });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 language not changing completely
Press Windows key+i to open the Settings. Click Time & language. Click Region & language. Under Languages, click Add a language.
Read more >
Didn't work with defaultLanguage different than en? · Issue #27
On client, just read from cookie the lang or set to default locale.
Read more >
How to change system language on Windows 10
Change system region settings · Open Settings. · Click on Time & Language. · Click on Region. · Under the "Region" section, select...
Read more >
Change your language on the web - Computer - Google Support
Sign in to your Google Account. On the left, click Personal info. Under "General preferences for the web," click Language and then Edit...
Read more >
How to Change the System language across your ... - YouTube
You don't have to be stuck with the default Windows 10 language.If you prefer to use a different language, you can change it...
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