javascript - react JS i18n using in functions -
i have lots of functions 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 got error. -> t not function ..
because missing:
export default compose( translate('translations'), connect() )(languagechooser);
how can add translate('translations') part function?
thanks
the translate hoc needed components -> asserts components rerendered on translation change or if set component waits translation files loaded before initial render.
to use i18next inside function, just:
import i18n '../i18n'; // assuming got i18n instance configured , exported in samples - else import i18n '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 loaded translations before calling functions.
Comments
Post a Comment