Can't make i18n run

barbudito picture barbudito · Jan 28, 2016 · Viewed 9.2k times · Source

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

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...

Answer

AsGoodAsItGets picture AsGoodAsItGets · Mar 29, 2016

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