2

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.

Obed Parlapiano
  • 3,226
  • 3
  • 21
  • 39

1 Answers1

0

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.

Tomáš Ehrlich
  • 6,546
  • 3
  • 25
  • 31
  • Thank you! Yeah I figured after extensive research. I gave up and found an alternative solution of translating the file themselves and using locale folders to store/retrieve them, it's a shame though. – Obed Parlapiano Sep 15 '17 at 08:39
  • I have my app already in react-intl, maybe I'll switch it to something else in the future. – Obed Parlapiano Sep 15 '17 at 08:40