标签: i18n-node

node.js:有没有办法将HTML放入i18n-node JSON转换文件?

问题就是这一切.如果我将HTML直接放入(JSON格式的)翻译文件中,如下所示:

"test_html" : "click <a href='http://stackoverflow.com/'>here</a>",
Run Code Online (Sandbox Code Playgroud)

我在HTML中得到了这个:

click &lt;a href=&#39;http://stackoverflow.com/&#39;&gt;here&lt;/a&gt;
Run Code Online (Sandbox Code Playgroud)

我也试过在我的翻译文件中结合这个:

"test_html_placeholder" : "click %shere%s",
Run Code Online (Sandbox Code Playgroud)

在我的HTML中:

<%= __('test_html_placeholder', '<a href="http://stackoverflow.com">', '</a>') %>
Run Code Online (Sandbox Code Playgroud)

但得到了类似的结果.

我唯一可以上班的就是这种笨拙:

"test_html_pre" : "click ",
"test_html_link" : "here",
"test_html_post" : ".",
Run Code Online (Sandbox Code Playgroud)

有了这个:

<%= __('test_html_pre') %><a href="http://stackoverflow.com"><%= __('test_html_link') %></a><%= __('test_html_post') %>
Run Code Online (Sandbox Code Playgroud)

但它几乎不值得这么麻烦,而且在某些语言中的单词顺序会迫使我在我的翻译文件中放入一些空字符串,i18n-node似乎不喜欢它,因为它吐出了密钥(属性)遇到空字符串时的名称.

我也尝试使用"\"作为符号前面的转义字符,但是当我抬起风帆(重启服务器)时,我收到了无效的JSON错误.

任何想法,解决方法?我正在使用sails.js,这不是我的决定,但我坚持使用它,它带有i18n节点.在这个项目的当天晚些时候考虑使用另一个库,但并非完全不可能.

html anchor node.js sails.js i18n-node

8
推荐指数
1
解决办法
2179
查看次数

如何在 i18n-node 中创建一个文件夹并拥有多个相同语言的 json 文件?

我看过一个coursera 的视频,其中演讲者说在 locales 文件夹中,他们有每种语言的文件夹,在文件夹 language 中,有每个页面的 json 文件。

所以我的问题是如何在 i18n 中实现它?

模式示例:

app.js
--locales
----en
------home.json
------about.json
----de
------home.json
------about.json
Run Code Online (Sandbox Code Playgroud)

谢谢你!

json internationalization i18n-node

5
推荐指数
0
解决办法
482
查看次数

node.js i18n:“ReferenceError:__未定义”

在我的整个应用程序中,我使用起来i18n没有问题。但是,对于通过 cron 作业发送电子邮件,我收到错误:

引用错误:__ 未定义

app.js我配置 i18n 中:

const i18n = require("i18n");
i18n.configure({
    locales: ["en"],
    register: global,
    directory: path.join(__dirname, "locales"),
    defaultLocale: "en",
    objectNotation: true,
    updateFiles: false,
});
app.use(i18n.init);
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我将其用作__('authentication.flashes.not-logged-in'),就像我说的那样,没有任何问题。在由 cron 作业调用的邮件控制器中,我以相同的方式使用它:__('mailers.buttons.upgrade-now')。然而,只有在那里,它才会产生上述错误。

只是为了尝试,我已在邮件控制器中将其更改为i18n.__('authentication.flashes.not-logged-in'). 但后来我收到另一个错误:

(node:11058) UnhandledPromiseRejectionWarning: TypeError: logWarnFn is not a function
    at logWarn (/data/web/my_app/node_modules/i18n/i18n.js:1180:5)
Run Code Online (Sandbox Code Playgroud)

知道如何使通过 cron 作业发送的电子邮件正常工作吗?

cron internationalization node.js i18n-node

3
推荐指数
1
解决办法
3598
查看次数

标签 统计

i18n-node ×3

internationalization ×2

node.js ×2

anchor ×1

cron ×1

html ×1

json ×1

sails.js ×1