Javascript 用于react组件的阵列元素的i18n
我想使用Javascript 用于react组件的阵列元素的i18n,javascript,reactjs,meteor,internationalization,Javascript,Reactjs,Meteor,Internationalization,我想使用universe:i18n翻译我的meteor应用程序(使用react) 在这个组件中,您可以看到,我使用map()遍历了一个数组,作为输出,我希望将类别作为翻译: 导入/ui/components/example.jsx import React, { Component } from 'react' import i18n from 'meteor/universe:i18n' clas
universe:i18n
翻译我的meteor应用程序(使用react)
在这个组件中,您可以看到,我使用map()
遍历了一个数组,作为输出,我希望将类别作为翻译:
导入/ui/components/example.jsx
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>
);
}
}
我试着用它来做
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>
);
}
}
const T=i18n.createComponent()
类示例扩展组件{
getCategories(索引){
常量类别=[“一”、“二”、“三”];//{
返回(
类别[{this.getCategories(i.index)}]
);
}) }
);
}
}
它不起作用,因为必须使用点而不是括号符号,所以
<T>categories.{ this.getCategories(i.index) }</T>
<T>categories.{ this.getCategories(i.index) }</T>
<T>categories[{ this.getCategories(i.index) }]</T>
<T children={`categories.${ this.getCategories(i.index) }`} />