-
-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18next properties dont seem to do anything (nonExplicitSupportedLngs does not redirect to closest locale) #1412
Comments
All handling of locales is done by NextJs directly. If you want |
What are the i18next properties for, then? Do I even pass them at the correct position? @isaachinman |
The i18next properties all work as normal, with the caveat that NextJs dictates the current locale, as it handles internationalised routing. Hope that makes sense. |
Makes sense. Can I somehow implement a custom language detection function? Seems like it was possible with older versions of this library (#208). If not, are there any plans on supporting that again? Thanks a lot for taking your time for me! |
Not at the moment, to my knowledge.
Yes, that's correct. Previously, Therefore, any detection or routing concerns should be forwarded to the NextJs repo. |
Understood, thanks a lot! |
As a quick update, in case anyone stumbles upon this issue later on, I solved it using next's Your implementation may vary, but it should essentially boil down to something like this: export const getServerSideProps: GetServerSideProps = async ({
req,
locale,
locales
}) => {
// Read the accepted locales from the headers
const acceptedLanguages = req.headers['accept-language'];
const acceptedLocales = getLocales(acceptedLanguages);
// Find matching locale/language from the available locales
const foundLocales = getMatchingLocales(acceptedLocales, locales!);
if (foundLocales.length !== 0 && foundLocales[0] !== locale) {
return {
redirect: {
permanent: false,
destination: `/${foundLocales[0]}`
}
};
}
return {
props: {
...(await serverSideTranslations(locale!, ['common']))
}
};
}; |
I am going to add two notes to @MauriceNino last comment to help people who stumbles on this problem.
// next-i18next.config.js
const path = require('path');
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
nonExplicitSupportedLngs: true,
localePath: path.resolve('./public/locales'),
},
};
// helpers/localisation.ts
export const getServerSideProps: GetServerSideProps = async ({ req, locale, locales }) => {
...
}; // All pages except for 404
import { getServerSideProps } from 'helpers/localisation';
...
export { getServerSideProps };
export default CurrentPage; |
Describe the bug
I want to support sub-locales. So for example, if someone calls my website with
Accept-Language: de-DE
, thende
should be loaded.For this, there seems to be the property
nonExplicitSupportedLngs
in i18next. I tried adding it to the config, but it is being ignored.Occurs in next-i18next version
v8.7.0
Steps to reproduce
This commit on my repository has the "bug": MauriceNino/portfolio@792997f
You can also send a GET request against the live version:
The text was updated successfully, but these errors were encountered: