2017-02-03 10 views
1

私の流星群の翻訳にはuniverse:i18nを使っています(反応を使って)。反応成分の配列要素のためのi18n

輸入/ UI /コンポーネント/ example.jsx

:私は map()を使用して配列を反復処理し、出力として、私は翻訳などのカテゴリを取得したいと思いあなたが見ることができます。このコンポーネントでは、

import React, { Component }     from 'react' 
import i18n         from 'meteor/universe:i18n' 

class Example extends Component { 
    getCategories(index) { 
     const categories = [ 'one', 'two', 'three' ]; // <-- Get correct translations of these elements 
     return categories[index - 1]; 
    } 

    render() { 
     return (
      <div id="content"> 
       { this.props.sections.map((i) => { 
        return (
         <div> 
          { this.getCategories(i.index) } 
         </div> 
        ); 
       }) } 
      </div> 
     ); 
    } 
} 

I18N/de.i18.json

{ 
    categories: { 
     one: 'Eins', 
     two: 'Zwei', 
     three: 'Drei' 
    } 
} 

私はあなたの代わりにbracker表記のドットを使用する必要があるため、それは動作しません

const T = i18n.createComponent() 

class Example extends Component { 
    getCategories(index) { 
     const categories = [ 'one', 'two', 'three' ]; // <-- Get correct translations of these elements 
     return categories[index - 1]; 
    } 

    render() { 
     return (
      <div id="content"> 
       { this.props.sections.map((i) => { 
        return (
         <div> 
          <T>categories[{ this.getCategories(i.index) }]</T> 
         </div> 
        ); 
       }) } 
      </div> 
     ); 
    } 
} 

答えて

2

でそれを実行しようとしました代わりに

<T>categories[{ this.getCategories(i.index) }]</T> 

のよう

<T>categories.{ this.getCategories(i.index) }</T> 

しかし、配列はchildrenとなり、文字列のみが受け入れられるので、まだ動作しません。このように使用してください:

<T children={`categories.${ this.getCategories(i.index) }`} /> 

Source

関連する問題