使用nodejs时的i18下一段

时间:2013-02-08 23:35:34

标签: javascript internationalization i18next

我使用的http://jamuhl.github.com/i18next/node/工作正常,但对于一个我无法想象如何解决它的问题。

就是这样,我在/locales/dev/translation.json中有这个translation.json文件

{
  "tzm": "Chapters - Zeitgeist Movement"
  ,"welcome": [
    "<p>The Zeitgeist Movement is an explicitly non-violent, global sustainability advocacy group currently working in over 1000 Regional Chapters across 70 countries.</p>"
    ,"<p>The basic structure of The Movement consists of Chapters, Teams, Projects & Events. Overall, the Chapters are essentially what define the Movement and each Chapter works to not only spread awareness about the roots of our social problems today but also to express the logical, scientific solutions and methods we have at our disposal to update and correct the current social system and create a truly responsible, sustainable, peaceful, global society.</p>"
  ]

在我的刀片模板中,我有以下内容:

div#page
   p=t("welcome")

问题是我得到了html标签,看着专门设置内部html的文档http://i18next.com/pages/sample.html

使用i18next-node和显示段落部分的正确方法是什么,我以前做过的方式如下:

  ,"welcome": {
    "p1":"The Zeitgeist Movement is an explicitly non-violent, global sustainability advocacy group currently working in over 1000 Regional Chapters across 70 countries."
    ,"p2":"The basic structure of The Movement consists of Chapters, Teams, Projects & Events. Overall, the Chapters are essentially what define the Movement and each Chapter works to not only spread awareness about the roots of our social problems today but also to express the logical, scientific solutions and methods we have at our disposal to update and correct the current social system and create a truly responsible, sustainable, peaceful, global society."
  }

然后我的page.blade模板看起来像:

div#page
   p=t("welcome.p1")
   p=t("welcome.p2")

这适用于小型数据集,但如果您有大量段落,则可能会变得无聊。

3 个答案:

答案 0 :(得分:0)

想知道,但不应该像

div#page
    p!=t("welcome")

至少在玉器中,设置未转义的内容会是这样的。

我会使用node-blade提供的降价过滤器来获取纯文本内容。

答案 1 :(得分:0)

我做了这个并且它有效,虽然您可以在页面加载时看到初始<p>,然后显示段落。你可以看到它http://blade.eu01.aws.af.cm/

p(data-i18n="[html]welcome")=t("welcome")

答案 2 :(得分:0)

我查看了你的页面。它确实以这种方式添加了两个段落。一个用p(data-i18n =“...”),另一个用p!= t(“welcome”)。对我来说,这似乎是与刀片模板引擎相关的问题。我会在那里打开一个问题。