Skip to content

Dynamic translation keys from json are not extracted #208

@k0pper

Description

@k0pper

I am building a gatsby website that holds some data in data/technologies.json:

[
   {
      "shortName": "Frontend",
      "longName": "Frontend Development",
      "descriptionPath": "leistungen.techstack.frontend"
   }
]

In the render method, I have code that is fetching this data with graphQL and sets the current selected element.

// get data
const techStacks = useStaticQuery...

// get current selected element
const techStack = techStacks[currentIndex]

Now, I want to use this descriptionPath field to insert as a translation key:

<FormattedMessage
	id=techStack.descriptionPath
	defaultMessage="This message should be extracted"
></FormattedMessage>

But when I run formatJS to extract these defaultMessages into a language file, an arbitrary key gets generated...

formatjs extract 'src/**/*.tsx' --out-file src/intl/de.json --format simple 
// should be "leistungen.techstack.frontend": "This message should be extracted"
"rnIXQm": "This message should be extracted"

Why is that? I can't be the only one with this problem. I feel like iterating over an array with data that should be dynamically translated is very common. Really hope someone can assist me with that.

Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions