i18n-extract
i18n-extract copied to clipboard
`findUnused` doesn't work with fully dynamic keys
I have this
const title = condition ? 'key:one' : 'key:two'
return t(title)
This is parsed as a dynamic key ('*'
) and catch all the keys for the findUnused
method. Hence the findUnused
returns nothing although I do have unused keys.
Can I propose a PR to exclude "fully" dynamic keys in the findUnused
method?
@Kerumen This module isn't smart enough to resolve the ternary. It's definitely something we could be improving!
@oliviertassinari Can we statically resolve the ternary? I have another dynamic key which is a mapping and this can be a bit harder to resolve.
My initial plan was to exclude the *
keys in the findUnused
method.
Can we statically resolve the ternary?
Yes, it should be possible: https://astexplorer.net/#/gist/8723b1d7635cc08968d33a1501c8f25c/96f58bc82bae32e48728f6eed25a90cb00d497d0.
My initial plan was to exclude the * keys in the findUnused method.
Having a *
in the list of keys makes the findUnused()
method useless. It's a good idea to work on removing it!
A large chunk of the effort has already been done in #39. What we miss is to explore the reference. It's definitely possible, for instance in https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/blob/b2f03bb50f5a6705e6ac26d988793d4ba9b0599c/src/isStatelessComponent.js#L61.
same * problem here
const translationBaseKey = 'pages.profile';
<Form.Input
type="text"
label={t(`${translateBaseKey}.userName`)}
value={username}
/>
returned key of this constallation : *.userName
existing translation : profilePage.userName = Username
expected : missing-test should tell me : pages.profile.userName unused-test should tell me : profilePage.userName
reality : neither missing nor unused is complaining an error
how to solve this problem? or do exists another testing module? cause i did found nothing comparable...
PS : working with jest to test