question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to load JSON file in loadPath

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Akki4141commented, Nov 14, 2017

Surely, I will give it a try.

0reactions
jamuhlcommented, Nov 14, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found