简体   繁体   English

无法让i18n运行

[英]Can't make i18n run

I am creating a website with HTML5 and CSS, not using CMS. 我正在使用HTML5和CSS创建网站,而不使用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 所以我选了i18next,但是我也尝试了i18n,i18next.amd ...现在我被卡住了,因为我在关注一些教程,无法使它正常工作...每当出现此错误

Uncaught ReferenceError: i18n is not defined 未捕获的ReferenceError:未定义i18n

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 index.html
  • locales 语言环境
    • en
      • translation.json translation.json
    • es es
      • translation.json translation.json
    • default 默认
      • translation.json translation.json
  • js js
    • jquery.min.js jquery.min.js
    • i18next.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: 所有的JSON文件都是这样的:

{
"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 我提到的教程: http : //i18next.github.io/i18next/ http://jsbin.com/yaxofuhuzu/1/edit?html,js,输出 www.davidhamannmedia.com/en/post-i18next-an-easy使用翻译javascript库

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. 该库的文档很乱,主要是因为作者决定将其从1.x版本重写为2.x,并且API发生了巨大变化。 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. 现在,您可以在http://i18next.com/docs/上找到的文档涉及版本2.x,而许多博客和stackoverflow文章均涉及版本1.x,这增加了混乱。 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). 更糟的是,我找不到1.x版的任何完整文档(顺便说一下,它还不到一年)。

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). 现在,要回答您的问题,您似乎正在使用的选项和API来自1.x版(例如, resGetPath在2.x版中不存在)。 Also, in 2.x, i18n has been replaced by i18next . 另外,在2.x中, i18n已被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. 从好的方面来说,作者似乎对问题的回答很快,因此您最好在项目github页面上打开一个问题。 Or check this: 或检查此:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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