1

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 ..

because this is missing:

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

how can I add the translate('translations') part to a function?

thanks

6
  • If you are using dialogContent as a component it is stateless. So no state, this, etc. Commented Jul 28, 2017 at 7:15
  • Problem is that I need this part translate('translations'), in my function Commented Jul 28, 2017 at 7:15
  • Then just add it :) . How do you use dialogContent? Commented Jul 28, 2017 at 7:16
  • but where and how? dialogContent is an exported function, I bind it in the constructor of a component Commented Jul 28, 2017 at 7:17
  • 1
    Plz add the part where you use the function otherwise the question is not clear and not useful for future readers. You need to use translate HOC on the component where you are using dialogContent Commented Jul 28, 2017 at 7:20

1 Answer 1

15

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.

To use i18next inside a function, just:

import i18n from '../i18n'; // assuming you got an 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.

Sign up to request clarification or add additional context in comments.

1 Comment

cont { t } = i18n;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.