React-i18next: Change default language by page

Created on 25 Oct 2018  路  8Comments  路  Source: i18next/react-i18next

i am new for using nextjs.

For my site, each user contains his language. For the nextjs example, i found that i has auto language detection.

If the user login, the site use the user's language.
If the user does not login, the site auto detech the language.

How can i setup this feature?
Thanks

next.js / SSR question

All 8 comments

see:

https://github.com/i18next/i18next-express-middleware#language-detection -> for serverside

https://github.com/i18next/i18next-browser-languageDetector -> for clientside

if the user language is not match the language in cookie or session, how can I change language in slience?

Hm...i'm rather sure it's in the docs.

There is the i18n.changeLanguage or better adding a custom_detector for detecting it. Custom detection is described in the above links.

Thanks. i change the language on componentDidMount in _app.js

i try to move all locales into other folder called 'assets'. i changed all path.
But, found the following issue.

ajax.js:71 GET http://localhost:3000/assets/locales/en/common.json 404 (Not Found)

any idea?

did you change that: https://github.com/i18next/react-i18next/blob/master/example/nextjs/server.js#L70 to assets/locales -> to make that folder hosted

Thanks. Solved it

And don鈥檛 forget to star this repo. Make a tweet or have a look at our https://locize.com -> there are many ways to help this project :pray:

Was this page helpful?
0 / 5 - 0 ratings