简体   繁体   中英

Can't make i18n run

I am creating a website with HTML5 and CSS, not using CMS. My next goal was to make the website in many languages so I searched and found many libraries. I am newbie to this and went for the easiest one or the one with more comments, examples...

So I took i18next, but I also tried i18n, i18next.amd... Right now I am stuck because I was following a few tutorials and cant make this work... Everytime I get this error

Uncaught ReferenceError: i18n is not defined

So I created an empty project just to make this work and learn how to do it. This new project is really light. The structure is:

  • index.html
  • locales
    • en
      • translation.json
    • es
      • translation.json
    • default
      • translation.json
  • js
    • jquery.min.js
    • i18next.min.js

 <html> <head> <meta charset="utf-8"> </head> <body> <script type="text/javascript" src="js/jquery.min.js" ></script> <script type="text/javascript" src="js/i18next.min.js" ></script> <script type="text/javascript"> var options ={ lng: "en" , resGetPath: './../locales/__lng__/__ns__.json' }; i18n.init(options, function(t) { $(".nav").i18n(); }); </script> <ul class="nav"> <li><a href="#" data-i18n="nav.home">asd</a></li> <li><a href="#" data-i18n="nav.page1">asd</a></li> <li><a href="#" data-i18n="nav.page2">asd</a></li> </ul> </body> </html> 

and all of the JSON files are like this:

{
"app": {
"name": "i18next"
},
"nav": {
"home": "Home",
"page1": "Page One",
"page2": "Page Two"
}
}

I wish someone can help me, and I will really appreciate. (sorry for my english btw)

Tutorials I mentioned: http://i18next.github.io/i18next/ http://jsbin.com/yaxofuhuzu/1/edit?html,js,output www.davidhamannmedia.com/en/post-i18next-an-easy-to-use-translation-javascript-library

And many more...

The documentation for this library is a mess, mostly because the author decided to rewrite it from version 1.x to 2.x and the API has changed drastically. The documentation you can now find on http://i18next.com/docs/ refers to version 2.x, while a lot of the blog and stackoverflow articles refer to version 1.x, adding to the confusion. To add insult to injury, I can't find any complete documentation for version 1.x anymore (which by the way, is less than a year old).

Now, to answer your question, the options and API you seem to be using are from version 1.x (for example, resGetPath doesn't exist in version 2.x). Also, in 2.x, i18n has been replaced by i18next .

On the bright side, the author seems to reply fast to questions, so you might as well open an issue on the project github page. Or check this:

https://github.com/i18next/i18next/issues/618

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM