i18next: i18next::backendconnector failed to load json from the backend

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?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (10 by maintainers)

Most upvoted comments

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.

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

Hi @jamuhl, I am also encountering this warning when the path is something like /sample/route but when the path is just /sample, it’s working fine. All of the json files are in the public directory.

thanks for the reply. I will have a look.