react i18n outside component

I want to translate every promp in the Questions arrays.

I am new to this but I couldn't find a usefull solution to this online. Best I could find is that code below:

When I run like this it doesn't render at the beginning

import i18n from "i18next";

const aFunction = (pr) => {
  return i18n.t(pr);
};

export const Questions = [
  {
    promp: aFunction("translation1"),
    type: "A",
    type2: "AC",
  },
{
    promp: aFunction("translation2"),
    type: "A",
    type2: "AB",
  },
] 

Upvotes: 0

Views: 725

Answers (1)

I solved it. It was a really long progress with a simple answer.

Instead of translating in an array I used this:

<h1 className="q1">{i18n.t(Questions[cQuestion].promp)}</h1>

and with this I can easily do this:

{
    promp: "translation inside the json file",
    type: "A",
    type2: "AC",
  },```

Upvotes: 1

Related Questions