-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
How to support zh-tw, zh-cn, pt-br #1467
Comments
https://www.i18next.com/principles/fallback#language-fallback |
This worked, thanks! |
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project. There are many ways to help this project 🙏 |
@jinongun try and you will see - nothing todo with it |
My GoalRoute My Codesstrings.json i18n.ts import NextI18Next from 'next-i18next';
export const DEFAULT_LOCALE = 'en';
// NOTE: Keep `en` the first element of this list
export const AVAILABLE_LOCALE_LIST = ['en', 'zh-TW'];
const nextI18NextInstance = new NextI18Next({
defaultLanguage: DEFAULT_LOCALE,
defaultNS: 'strings',
otherLanguages: AVAILABLE_LOCALE_LIST,
localeSubpaths: {
...AVAILABLE_LOCALE_LIST.reduce<{ [key: string]: string }>((acc, curr) => {
acc[curr] = curr;
return acc;
}, {}),
'zh-TW': 'tw'
}, // ex. { ar: 'ar', ... }
localeStructure: '{lng}/{ns}',
contextSeparator: '/',
pluralSeparator: '.',
nonExplicitSupportedLngs: true,
keySeparator: false,
load: 'currentOnly',
fallbackLng: {
'default': ['en']
},
interpolation: { prefix: '{', suffix: '}' },
debug: false,
detection: {
lookupCookie: 'locale',
lookupQuerystring: 'locale',
order: ['querystring', 'cookie', 'header'],
caches: ['cookie'],
cookieOptions: { path: '/', secure: true },
},
});
export const { appWithTranslation, withTranslation, i18n, Link, useTranslation, Router } = nextI18NextInstance;
export default nextI18NextInstance; The above code doesn't work. so, I've found 2 solutions. First solution Add
BUT, I don't have Second solution Toggle It looks okay for me. but if I can solve this problem without Could you give me some advice? |
Looks more related to next-i18next ---> ask over at the https://github.com/isaachinman/next-i18next repo |
@jamuhl Thanks a lot. By the way, which one looks a better solution you think? |
what you mean...next-i18next uses react-i18next under the hood...makes using it simpler with next.js |
@jamuhl I mean between 2 solutions which I've found. |
nonExplicitSupportedLngs:false should be ok as long your list is complete ;) |
@jamuhl Do you mind giving some examples for me about the |
It's rather simple...as saying in the docs: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources supportedLngs: array of allowed languages => every specific locale (lng-(script)-Region) will pass if supportedLngs has the unspecific locale lng (without region) ---> so having |
@jamuhl I have I expected to route |
no... again: supportedLngs: array of allowed languages nonExplicitSupportedLngs -> changes which languages pass the isSupportedLng check https://www.i18next.com/principles/translation-resolution#languages |
@jamuhl I made a table for my situation. My browser is Each result means routed subpath.
In the It makes me confused. Am I misunderstanding now? |
sorry I don't understand your table...resolving locales has nothing todo with JSON files. Just check -> i18next.languages...this is the array of locales used in priority to lookup translations. load: currentOnly -> uses what is detected no fallback to the language part, eg. zh-TW -> zh-TW, en how subpath works, idk. you will have to ask at the next-i18next repo |
fixes #16805 - turns out i18next requires the country portal of the locale to be capitalized [1] - this resolves that and moves the files to the correct name [1]: i18next/i18next#1467 (comment)
fixes #16805 - turns out i18next requires the country portal of the locale to be capitalized [1] - this resolves that and moves the files to the correct name [1]: i18next/i18next#1467 (comment)
fixes #16805 * turns out i18next requires the country portal of the locale to be capitalized [1] * this resolves that and moves the files to the correct casing [1]: i18next/i18next#1467 (comment)
fixes #16805 * turns out i18next requires the country portal of the locale to be capitalized [1] * this resolves that and moves the files to the correct casing [1]: i18next/i18next#1467 (comment)
We have this set up in our backend
Now we have our local folders set up as
_
_
but the browser gives me this error on debug
So it wont look for the zh-tw folder but instead only does the zh folder. Same result happens with pt-br, it looks for the folder pt.
After that error it shows (but still doesnt translate sincefile cant be parse since it cant be found)
Is there anyway to fix this?
The text was updated successfully, but these errors were encountered: