3

this is my code at index.html

<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
    <script src="javascript/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="javascript/i18next-1.7.4.js" type="text/javascript"></script>

    <title>i18next test</title>
</head>

<body>
    <p id="id001" data-i18n="first_data">first</p>
</body>

<script type="text/javascript">

$(document).ready(function(){
  language_complete = navigator.language.split("-");
  language = (language_complete[0]);

  i18n.init({
  lng: language, 
  resGetPath: 'locales/__lng__.json',
  fallbackLng: "en",
  }, function(){
    $("first_data").i18n();
  });

});
</script>

</html>

And I've created 2 json file at the same directory with index.html

locales/en.json
locales/de.json

json file content:

{
    "first_data": "de-first-data"
}

Firefox try to load de.json and en.json but get the error 404. enter image description here

Do you have any idea why i18next cannot load the json file.

This is my folder structure below:

index.html
locales/de.json
locales/en.json
javascript/i18next-1.7.4.js
javascript/jquery-1.11.1.min.js
ybdesire
  • 1,593
  • 1
  • 20
  • 35

2 Answers2

2

You host application in IIS. IIS by default (as far as I know) doesn't support JSON file type.

Following question is related to same problem: ERROR 404.3 Not Found for JSON file

Community
  • 1
  • 1
Marian Polacek
  • 2,906
  • 4
  • 30
  • 37
  • Thanks drax for the help. The json file can be loaded correctly by IIS setting to support json. I've tried to replace '$("first_data").i18n();' to '$("#first_data").i18n();' and '$('.i18n').i18n();' But the data-i18n data still cannot be replaced by translation at related non-EN json file. – ybdesire Dec 08 '14 at 09:50
  • You have to use correct selector, element that you want to translate has id 'id001', so $("#id001").i18n() would be correct call for this case. – Marian Polacek Dec 08 '14 at 10:03
0

Have you tried with ?

resGetPath: 'javascript/locales/__lng__.json',
Aston
  • 225
  • 1
  • 7