Comments (9)
The problem is probably const prodLoadPath = getCdnUrl(
${path}/${locale}.json);
. This line of code is not executed again when the locale changed? So if the value of that locale variable is initialized with ja, it will always only load ja translations. And since you have "http://127.0.0.1:3000/src/i18n/locales/{{lng}}.json"
in dev when working locally, it works. So it does not work only when deployed.
The loadPath should always include {{lng}}
.
from i18next-http-backend.
Would the addPath
not load the hardcoded en.json
in addition here?
const addPath = isDev
? "http://127.0.0.1:3000/src/i18n/locales/en.json"
: getCdnUrl(`${path}/en.json`);
The locale is set on page load and is not changed again. However, I would expect the fallbackLng to also be imported, in the case of missing strings in the non-English translation files (we usually have a few days' lag time for getting back translations for non-en
locales, so I need the fallbackLng loaded as well).
from i18next-http-backend.
The addPath is only used for missingKeys... when saveMissing is set to true => https://www.i18next.com/overview/configuration-options#missing-keys (this has nothing to do with loading)
Regarding the fallback loading, yes that should work when setting the fallbackLng
option. => https://www.i18next.com/principles/fallback#fallback-to-different-languages
You may check if there are other warnings in your console output.
Also make sure the key containers.LeftPanel.ResourceView.component
really exists.
from i18next-http-backend.
I've confirmed the keys exist and are correct.
So I now have this as my options, with saveMissing
now set to true:
const loadPath = isDev
? "http://127.0.0.1:3000/src/i18n/locales/{{lng}}.json"
: prodLoadPath;
const addPath = isDev
? "http://127.0.0.1:3000/src/i18n/locales/en.json"
: getCdnUrl(`${path}/en.json`);
void i18nInstance
.use(Backend)
.use(initReactI18next)
.init<HttpBackendOptions>({
// https://github.com/i18next/i18next-http-backend#backend-options
backend: {
loadPath,
addPath,
},
lng: locale,
fallbackLng,
debug: true, // set to `true` to debug locally
returnNull: false,
saveMissing: true,
react: {
// react-i18next options
useSuspense: true,
},
interpolation: {
escapeValue: false, // not needed for React as it escapes by default
},
} as InitOptions);
But I'm still seeing the en
strings actually being ja
, despite the correct paths here:
from i18next-http-backend.
Ah, ok, I did just notice this error:
I don't understand why it's failing to fetch the en.json
file when it gets the ja.json
file from the exact same URL just file.
from i18next-http-backend.
Check your network tab and check the translation requests and responses... There might still be some issue in your setup. Maybe also your CORS setup.
Not easy to help without a reproducible example.
I can just say and confirm i18next and i18next-http-backend works as expected.
There's not much I can help with more than that, sorry...
from i18next-http-backend.
Thanks @adrai, you helped me narrow down the problem and at least confirm that the setup is correct and it's something about my env. Thank you!
from i18next-http-backend.
Hey @bildungsroman can you tell me how to fix this issue ? I am facing the exact same issue and not able to debug it further.
from i18next-http-backend.
It was an issue with our CDN @ajitesh13. Here is my currently working code:
export function loadI18n(logger: ILogger, locale: Locale, loadPath: string) {
const i18nInstance = createInstance();
const fallbackLng: Locale = "en";
void i18nInstance
.use(Backend)
.use(initReactI18next)
.init({
// https://github.com/i18next/i18next-http-backend#backend-options
backend: {
loadPath, // "src/i18n/locales/{{lng}}.json";
addPath: (lng: string, namespace: string) => {
logError(logger, `Missing locale ${lng} for namespace ${namespace}`);
},
},
load: "currentOnly",
lng: locale,
fallbackLng,
debug: false, // set to `true` to debug locally
returnNull: false,
react: {
useSuspense: false,
},
interpolation: {
escapeValue: false, // not needed for react
},
} as InitOptions);
return i18nInstance;
}
from i18next-http-backend.
Related Issues (20)
- Value for reloadInterval? HOT 1
- Failed to load path from API to get translation content HOT 8
- Module not found: Can't resolve 'encoding' in '.../node_modules/node-fetch/lib' HOT 6
- Version 2.2.1 loadpath variable can't be override HOT 14
- loadPath arguments in custom request function HOT 4
- Could not find a declaration file for module 'i18next-http-backend' HOT 2
- browser refuses to load files with credentials in url HOT 4
- Possibility to add timeout to the setup HOT 2
- Initial fetch call on vite serve mode HOT 2
- Module '"i18next-http-backend"' has no exported member 'RequestCallback'. HOT 2
- Translate the REST API content using axios HOT 9
- reloadInterval not working for multiple translation files HOT 6
- No request is sent to load a translation file if a website url includes basic auth credentials HOT 3
- have fetch pluggable HOT 5
- cross-fetch leaks to client-side bundle HOT 1
- Have a way to handle errors HOT 3
- backend request doesn't work HOT 5
- react-i18next and i18next-http-backend - how to do a single REST API call and fetch the namespaces from that response HOT 1
- HTTP Backend's reload doesn't work after initial failed fetch HOT 7
- Failed request to load remote resources aborts future reloads HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18next-http-backend.