加载页面时,我想将默认语言设置为'lt'并在Translate标记中写入'Početna',但是我收到错误提示,缺少语言翻译 '缺少translationId:语言的pocetna:$ {languageCode}'
第一次在标签中选择语言“ Latinica”时,我得到了很好的翻译,“ Translate”标签写了正确的名称“Početna”,但是当我要更改语言时,必须选择并在选择菜单中的语言上单击两次。例如,我单击“ Cirilica”语言,然后仍然保持“Početna”,然后第二次单击“ Cirilica”,然后获得正确的翻译“Почетна”。同样的事情是当我想更改“ Latinica”上的语言时< / p>
有人可以帮助我吗?这是我的代码...
class MainApp extends React.Component {
constructor(props){
super(props);
this.state = {
slag: 'lt',
translations : {
pocetna: ['Početna', 'Почетна'],
farewell: ['Dovidjenja', 'Довиђења']
}
}
this.props.initialize({
languages: [
{name: "Latinica", code: "lt"},
{name: "Cirilica", code: "cr"}
],
options: {
renderToStaticMarkup,
defaultLanguage: 'lt'
}
});
this.props.addTranslation(this.state.translations);
this.props.setActiveLanguage(this.state.slag);
this.onChangeLanguage = this.onChangeLanguage.bind(this);
}
onChangeLanguage(_slag) {
console.log('onChangeLanguage: ', _slag.value)
this.setState({slag: _slag.value})
this.props.setActiveLanguage(this.state.slag);
}
render() {
const languageInSelect = [
{ label: 'Latinica', value: 'lt' },
{ label: 'Cirilica', value: 'cr' }
];
return(
<Router>
{/* Lucida Console, Monaco, monospace */}
<div className="container-fluid" style={{'fontFamily':'Arial'}}>
<Route path='/login' component={Login} />
<PrivateRoute path='/' component={App} />
<div style={{'width': '300px', 'marginLeft': '645px'}}>
<Translate id="pocetna"></Translate>
<Select
onChange={this.onChangeLanguage}
options={languageInSelect}
defaultValue={{label: 'Latinica', value: 'lt'}}
/>
</div>
</div>
</Router>
);
}
}