[英]react JS i18n using in functions
I have lots of functions like this: 我有很多这样的功能:
export function dialogContent() {
const { t, i18n } = this.props;
switch (this.state.dialogHandlerVariable) {
//Delete changeLog
case 0:
return (<div> {t("dialog.dashboard.changelog.deleteChangelog.body")}</div>);
}
}
but here I got an error. 但是这里我有一个错误。 -> t is not a function .. -> t不是函数..
because this is missing: 因为这是缺少的:
export default compose(
translate('translations'),
connect()
)(LanguageChooser);
how can I add the translate('translations') part to a function? 我怎样才能将translate('translations')部分添加到函数中?
thanks 谢谢
the translate hoc is only needed for components -> it asserts components get rerendered on translation change or if set so the component waits for translation files to be loaded before initial render. 仅组件需要translate hoc->它断言在转换更改时或如果设置了转换就重新渲染组件,以便组件在初始渲染之前等待加载翻译文件。
to use i18next inside a function, just: 在函数内使用i18next,只需:
import i18n from '../i18n'; // assuming you got a i18n instance configured and exported like in the samples - else just import i18n from 'i18next';
export function dialogContent() {
const t = i18n.t;
switch (this.state.dialogHandlerVariable) {
//Delete changeLog
case 0:
return (<div> {t("dialog.dashboard.changelog.deleteChangelog.body")}</div>);
}
}
Just make sure you loaded the translations before calling your functions. 只需确保在调用函数之前加载了翻译即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.