javascriptreact-intl

Use of variables in keys instead of hard-coded value react-intl-universal-extract


How do you extract default messages with variables or constants in the key or .get()

Example of message to extract

<p>
    {
      intl
        .get(`${PREFIX}.personal-form.name-field`)
        .defaultMessage('First name')
    }
</p>

Running react-intl-universal-extract against the code above doesn't extract default message.

However when inserting a hard-coded value instead of ${PREFIX}, a message gets extracted.

Any ideas or different approaches to this work without any hard-coded values?


Solution

  • Since I couldn't find a direct solution to this issue.

    A workaround that helped me is by using the hard-coded string value instead of variable/constant name inside the get method.