Failed to load JSON file in loadPath
See original GitHub issueHi I am new to 18next module and trying to learn it. I have made very simple page to understand the working. My Directory structure is :
|--languages
|--locales
|--en.json
|--de.json
|--main.html
|-myscript.js
Here are the following files:
main.html:
<script src="https://unpkg.com/i18next/i18next.js"></script>
<script src="https://unpkg.com/i18next-xhr-backend/i18nextXHRBackend.js"></script>
<script src="https://unpkg.com/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.js"></script>
<script src="./myscript.js"></script>
<div style="height: 150px">
<button onclick="i18next.changeLanguage('en')">
english
</button>
<button onclick="i18next.changeLanguage('de')">
german
</button>
<li id="text">HELLO</li>
</div>
myscript.js:
i18next
.use(i18nextXHRBackend)
.use(i18nextBrowserLanguageDetector)
.init({
lng: 'en',
debug: true,
backend: {
loadPath: './languages/locales/{{lng}}.json',
}
}, function(err, t) {
// init set content
updateContent();
});
function updateContent() {
console.log(document.getElementById('text').textContent);
document.getElementById('text').textContent = i18next.t(document.getElementById('text').textContent);
}
function changeLng(lng) {
i18next.changeLanguage(lng);
}
i18next.on('languageChanged', () => {
updateContent();
});
en.json:
{
"HELLO": "HELLO"
}
de.json:
{
"HELLO":"HOLA"
}
But on the browser, the error is coming that it is failing to load resources and the text is also not changing. Can somebody tell where I am going wrong?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
i18next backend loadPath fails to map the data - Stack Overflow
The loadPath function is just there to get the path to load, not the actual load request. enter image description here.
Read more >Loading remote catalog.json ignores {} in load path
Hello. I'm trying to load an adressable catalog created in a separate project, but I'm getting an "Unable to open archive file" error...
Read more >Spark Read Json From Amazon S3
To read JSON file from Amazon S3 and create a DataFrame, you can use either spark.read.json("path") or spark.read.format("json").load("path") , ...
Read more >Dart Sass Command-Line Interface
It considers any file that's transitively imported through a load path to be a “dependency”. This flag doesn't affect the @warn rule or...
Read more >auth package - gitlab.com/rwxrob/auth - Go Packages
func (a App) JSON() []byte; func (a *App) Load(path string) error; func (a *App) Parse(buf ... UserConfigDir will be checked for an auth/config.json...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Surely, I will give it a try.
yes of course, just chrome does not support xhr to local filesystem -> open same file in eg. firefox evtl. safari should work already: https://stackoverflow.com/questions/38344612/ajax-request-to-local-file-system-not-working-in-chrome
but that’s really a limitation of using local filesystem