簡體   English   中英

使用in函數反應JS i18n

[英]react JS i18n using in functions

我有很多這樣的功能:

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>);
    }
}

但是這里我有一個錯誤。 -> t不是函數..

因為這是缺少的:

export default compose(
    translate('translations'),
    connect()
)(LanguageChooser);

我怎樣才能將translate('translations')部分添加到函數中?

謝謝

僅組件需要translate hoc->它斷言在轉換更改時或如果設置了轉換就重新渲染組件,以便組件在初始渲染之前等待加載翻譯文件。

在函數內使用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>);
    }
}

只需確保在調用函數之前加載了翻譯即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM