Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to get flattened defaultMessage as an input to overrideIdFn #3537

Open
longlho opened this issue Apr 17, 2022 Discussed in #3525 · 1 comment
Open

Option to get flattened defaultMessage as an input to overrideIdFn #3537

longlho opened this issue Apr 17, 2022 Discussed in #3525 · 1 comment
Labels

Comments

@longlho
Copy link
Member

longlho commented Apr 17, 2022

Discussed in #3525

Originally posted by cl8n April 8, 2022
in my app I use a custom algorithm to generate message IDs. I've used babel-plugin-formatjs's overrideIdFn and formatjs extract's --format option to do this.

I discovered today that, since I'm also using the --flatten option on formatjs extract, the provided defaultMessages which I'm using to generate IDs are the flattened ones. the defaultMessage input to overrideIdFn is not flattened, so the ID ends up different for some messages.

my current workaround is to flatten defaultMessage as it comes into overrideIdFn:

defaultMessage = printAST(hoistSelectors(parse(defaultMessage)));

but this is now referring to internals of formatjs, and I don't think it should be required to read the source to get this behavior. debugging why some IDs weren't matching up took me a while 😅 so what I suggest is to add another option for babel-plugin-formatjs that would control whether the defaultMessage input to overrideIdFn is flattened.

maybe this isn't common enough of a use case though, I'm not sure. thanks!

@github-actions
Copy link

github-actions bot commented May 3, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant