gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
159 stars 37 forks source link

Be able to extract translations from strings and not only from t(string) #193

Open alanszp opened 3 years ago

alanszp commented 3 years ago

Is your feature request related to a problem? Please describe.

When using yup or other libraries, I want to give the library the translation path, but not the computed value, and then in the code use that path with the TFunction.

Ilustrative example:

yup.object({
    body: yup.string().required('errors.bodyIsRequired'),
})

Later on the code

t(errors.body)

In this case, i18next-extract won't know that errors.bodyIsRequired is a translation.

Describe the solution you'd like

Was thinking (but open to discussion) that if we can add a comment hint like // i18next-extract-string-is-translation or // i18next-extract-string-is-translation-next-line would help in this cases.

Describe alternatives you've considered

Was thinking how to configure customTransComponents for this case, but the problem is that there are many types and they are stored in node_modules. Woludn't be so sure how to make that work.

Additional context

eric-burel commented 3 years ago

This one seems covered by this documentation: https://i18next-extract.netlify.app/#/configuration?id=tfunctionnames You can add relevant yup calls as function names, like "string().required" in your example.

alanszp commented 3 years ago

Thanks for the comment! I think that it might be used, but can lead to potential errors if miss configured. And also if the implementation of the yup call handles multiple firms, it may also lead to problems.

I think that this hint is still usefull.