0

I have a JSON in this form

"description": "{\"en\":\"some text\",\"fr\":\"un autre text\"}",

I can access the english text in this way

 <Cell cellTitle='test' cellDescription={JSON.parse(rowData.description).en}

but when I use a variable that contains the current language, it dosen't works. I tried this

  render() {
     const lang = I18n.locale;
    return (
<Cell cellTitle='test' cellDescription={JSON.parse(rowData.description).lang}

or

<Cell cellTitle='test' cellDescription={JSON.parse(rowData.description).{lang}}

none of them worked. Can you help me solve the problem?

0

1 Answer 1

1

This is how you do it:

render() {
  const description = JSON.parse(rowData.description);
  const lang = I18n.locale;

  return (
    <Cell cellTitle='test' cellDescription={description[lang]} ... />
  )
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I don't know why but for me it dose not work without parsing the json. So the solution for me was JSON.parse(rowData.shortDescription)[currentLanguage]
I updated the answer, so if it works, you can accept it :).

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.