'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 1:[1]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tassisto