Use statically generates messages in React Intl

1.4k views Asked by At

I have an object that contains content for a page, I import it and try to use it like you'd use any object variable:

import {Variable} from 'data'
const message = defineMessages({
  message: {
    id: 'component.title',
   defaultMessage: Variable.title
  }
})

However, I get React Intl] Messages must be statically evaluate-able for extraction.. I googled a lot and found no solution to this. I'm using babel-plugin-react-intl to generate the locale files, and a contributor said that Babel can only parse simple statically messages

It's hard to believe there's no way to be able to import content from another file and have it translated. There must be a way, I couldn't come up with a solution and help would be appreciated.

1

There are 1 answers

2
Tom Ehrlich On

I struggled with the same problem by myself. As far as I know, there's no way to translate a content of a variable in react-intl.

If you're interested in alternative solutions, I wrote jsLingui i18n library and recently just added support for noop translations, which is exactly what you're looking for.