我以研究 meteor 为例https://github.com/meteor/simple-todos-react 我正在尝试添加多语言支持。 我创建了已翻译的文件。
在文件/imports/ui/App.jsx
中我添加了代码:
import i18n from 'meteor/universe:i18n';
i18n.setLocale('en-US');
const T = i18n.createComponent();
i18n.setLocale('en-US').then(function () {
console.log('hello');
});
在渲染方法中我添加了:
. . . .
render() {
return (
<div className="container">
<header>
<h1>Todo List ({this.props.incompleteCount})</h1>
<T>hello </T>
<T _locale='ru-RU'>hello </T>
<T tagType='h1'>hello </T>
. . . .
文件en-US.i18n.json
{ "hello": "hello world!" }
但不幸的是我还没有找到该文本没有被翻译为好的例子。 我做错了什么?
最佳答案
我认为你必须设置一个命名空间。 您的 JSON 文件应该类似于:
{
"messages" :{"hello": "hello world!" }
}
然后调用它:
<T>messages.hello</T>
关于javascript - 一起使用meteor.js、universe-i18n 和react-todos 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828256/