i18next::backendconnector failed to load json from the backend

See original GitHub issue

I’m trying to load the json from the backend using i18nextXHRBackend. But it throws the following error.

i18next::backendConnector: loading namespace special for language en failed failed parsing /locales/en/special.json to json

Java Spring boot project folder structure

Project src/main/resources locales en special.json es special.json File special.json { “key”: “hello world”
}

File Sample.html

<html>
<head>
<script src="../js/i18nextXHRBackend.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="../js/i18next.min.js"></script>
<script th:inline="javascript">

$(document).ready(function() {
 i18next
	   .use(i18nextXHRBackend) 
	  .init({
		lng: mdCurrLocale,
	    fallbackLng: 'en',
	    debug: true,
	    ns: ['special'],
	    "keySeparator": false,
       "nsSeparator": false,
        getAsync: false,
        defaultNS: 'special',
	       backend: {
	      loadPath: "/locales/{{lng}}/{{ns}}.json",
	      crossDomain: false
	     }  
	      
	  }, function(err, t) {
		  var text = i18next.t('Key');
		  alert(text);
 }); 
 </script>

</head>
</html>


The i18nextXHRBackend is unable to load the json file from the project folder(project/src/main/resources/locales/en/special.json)

Where the json file should be placed inside the project folder in order to make this work?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
jamuhlcommented, Aug 21, 2017

you need to assert:

a) the file is public reachable -> eg. http://localhost:3000/en/special.json (or domain your app runs) b) the file needs to be valid json format

i18next::backendConnector: loading namespace special for language en failed failed parsing /locales/en/special.json to json

says what ever was loaded was not in valid json -> check devtools in eg. chrome for the content that was loaded.

1reaction
mahmoudelshenawy123commented, Jul 29, 2022

the solution is just add / before the path in loadPath in i18n initi just like this loadPath: ‘/assets/locales/{{lng}}/translation.json’,

Read more comments on GitHub >

github_iconTop Results From Across the Web

loading namespace failed" when using react-i18next ...
i18next ::backendConnector: loading namespace billingAddress for language en failed failed parsing /locales/en/billingAddress.json to json.
Read more >
Add or Load Translations - i18next documentation
The range of backends is large from loading translations in the browser ... be set on initialization while others can be loaded using...
Read more >
loading namespace failed" when using react-i18next ...
[Solved]-"i18next backendConnector: loading namespace failed" when using ... Using xhr backend you need to provide valid JSON files as source - that's all....
Read more >
How to properly internationalize a React application using ...
Let's separate the translations from the code and pleace them in dedicated json files. Because this is a web application, i18next-http-backend will help...
Read more >
i18next::backendconnector failed to load json from the backend
i18next ::backendConnector: loading namespace special for language en failed failed parsing /locales/en/special.json to 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