Comments (4)
Yes, that's a limitation of the fetch api...
Just passt the requested authorization header like this:
useFactory: (i18next: ITranslationService) => () => i18next.use(HttpApi).init({
lng: "en",
backend: {
- loadPath: "assets/locales/{{lng}}.json",
+ loadPath: "http://localhost:4200/assets/locales/{{lng}}.json",
+ customHeaders: {
+ authorization: 'Basic ' + btoa('admin:admin')
+ }
}
}),
from i18next-http-backend.
mhmm, I've tried it manually using fetch and now I get a helpful error message (also listed in the fetch docs)
the problem here isn't that I'm trying to pass credentials, my problem is lazy users that bookmark urls with credentials (don't ask) and unknowingly break language file loading.
when I use fetch to request a path, the browser conveniently includes the "current url" which happens to include deprecated-style credentials if the user put them there
but I guess this is more of a general issue I need to work around, not one with the http backend. it just happened to be the first place I noticed it. sorry!
from i18next-http-backend.
Then define the loadPath to be absolute and not relative.
from i18next-http-backend.
you're right, I can just use
{
lng: "en",
backend: {
loadPath: `${window.location.href}assets/locales/{{lng}}.json`
}
}
it feels dirty, but it works. thanks!
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
- 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.