如何在 Sails.js 的 Bootstrap 中使用 i18n?
这是 Controller Action 中的“res.i18n”,但我没有找到像 sails.i18n 这样的全局实例(已经初始化)。
我想下面的代码应该可以在 bootstrap.js 中运行:
i18n = require('i18n'),
i18n.configure({
locales: sails.config.i18n.locales,
directory: sails.config.appPath + sails.config.i18n.localesDirectory,
defaultLocale: sails.config.i18n.defaultLocale,
updateFiles: false,
extension: '.json'
});
__('Hello');
但是否有更好的方法?
最佳答案
在 sails 中,已经为您设置了 i18n。您可以在 config/i18n.js
中配置 i18n,并在 config/locales/
目录中创建语言环境。
关于用法,对于您的 View ,您可以使用i18n()
或__()
。在您的 Controller 中使用res.i18n()
。 More on that can be found here .
关于global方法,可以调用sails.__()
。
关于node.js - Sails.js:如何在 Bootstrap 中使用 i18n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19088393/