i18next::backendconnector failed to load json from the backend
See original GitHub issueI’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:
- Created 6 years ago
- Comments:22 (10 by maintainers)
Top 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 >
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
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’,