我以研究流星为例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!" }
但遗憾的是,我没有找到这个文本。 我做错了什么?
答案 0 :(得分:0)
我认为您必须设置一个名称空间。 您的JSON文件应类似于:
{
"messages" :{"hello": "hello world!" }
}
然后通过以下方式调用它:
<T>messages.hello</T>