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.

Can't set localeDetection in the next-i18next.config

See original GitHub issue

I hope everything is alright since this is my very first report. I just tried to upgrade my nextjs application. Which worked fine so far. But when I try to build the application I get an error:

🐛 Bug Report

Type error: Argument of type '{ i18n: { locales: string[]; defaultLocale: string; localeDetection: boolean; }; debug: boolean; nonExplicitSupportedLngs: boolean; reloadOnPrerender: boolean; trailingSlash: boolean; }' is not assignable to parameter of type 'UserConfig'.
  Types of property 'i18n' are incompatible.
    Type '{ locales: string[]; defaultLocale: string; localeDetection: boolean; }' is not assignable to type 'NextJsI18NConfig'.
      Object literal may only specify known properties, and 'localeDetection' does not exist in type 'NextJsI18NConfig'.

To Reproduce

the next-i18next.config.js looks like this:

module.exports = {
  i18n: {
    locales: ['default', 'de', 'en'],
    defaultLocale: 'en',
    localeDetection: false,
  },
  debug: process.env.NODE_ENV === 'development',
  nonExplicitSupportedLngs: true,
  reloadOnPrerender: process.env.NODE_ENV === 'development',
  trailingSlash: true,
};

our _app.page.tsx looks like this:

import { appWithTranslation } from 'next-i18next';
import nextI18NextConfig from '../../next-i18next.config.js';
...

export default appWithTranslation(MyApp, nextI18NextConfig);

Expected behaviour

I would expect that the method appWithTranslation/UserConfig accepts the property localeDetection. Since nextjs would accept it by default. I used this approach to always have the language in the URL https://nextjs.org/docs/advanced-features/i18n-routing

Our Environment

node v16.14.0 “next”: “13.0.6”, “next-i18next”: “^13.0.0”, “i18next”: “^22.0.8”, “react-i18next”: “^12.0.0”,

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
adraicommented, Dec 13, 2022

changing that to boolean would not solve it… The problem is next.js itself is defining it as false here and here … and on the installed next.js version it is included in node_modules/next/dist/next-config-validate.js as boolean… This means the Vercel team (@Timer) needs to adapt their types first to be boolean instead of false everywhere.

2reactions
belgattitudecommented, Dec 8, 2022

Thx for mention, I’m still off a couple of days but I’ll read properly soon and see what we can do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Impossible to use language detection now (?) · Issue #1841
I'm trying to implement language detection based on query string. ... then sets it as lng property of i18next config which disables language...
Read more >
next-i18next detect locale with querystring
I want to detect locale from querystring. (www.example.com/detail?lang=en) But it does not work. next-i18next.config.js is already active in ...
Read more >
Advanced Features: Internationalized Routing
When localeDetection is set to false Next.js will no longer automatically redirect based on the user's preferred locale and will only provide locale...
Read more >
Configuration Options - i18next documentation
Set it to false if your backend loads resources synchronously - that way, calling i18next. t() after init() is possible without relying on...
Read more >
A Guide to React Localization with i18next
We'll see how we can load in resources asynchronously, and how to detect the user's language from the browser, a bit later. The...
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