【问题标题】:Example for meteor.js, universe-i18n and react-todos togethermeteor.js、universe-i18n 和 react-todos 的示例
【发布时间】:2016-11-27 11:12:03
【问题描述】:

我研究流星例如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!" }

但不幸的是,我没有找到文本并没有被翻译成很好的例子。 我做错了什么?

【问题讨论】:

  • 不应该将该文件称为 en-US 即使用连字符而不是使用下划线吗?
  • 好的,我正在更新,但它没有改变任何东西。
  • hello 之后有一个额外的空格 - 这可能是原因。
  • 您发现问题了吗?

标签: javascript reactjs meteor internationalization


【解决方案1】:

我认为你必须设置一个命名空间。 你的 JSON 文件应该是这样的:

{ 
    "messages" :{"hello": "hello world!" }
}

然后调用它:

<T>messages.hello</T>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-26
    • 2014-06-14
    • 1970-01-01
    • 2016-08-17
    • 2015-11-02
    • 2015-06-22
    • 2015-05-31
    • 2016-05-23
    相关资源
    最近更新 更多