i18next / i18next-parser

Parse your code to extract translation keys/values and manage your catalog files
MIT License
486 stars 198 forks source link

Add feature to skip identical keys for specified locales #1057

Open Aryan-mor opened 3 months ago

Aryan-mor commented 3 months ago

Implemented logic to skip keys with identical values for specified locales in the i18next parser. Fixes #1036

Why am I submitting this PR

Please refer to #1036

Does it fix an existing ticket?

Yes #1036

Checklist

codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.47%. Comparing base (168c8d5) to head (2a02abc). Report is 65 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1057 +/- ## ========================================== + Coverage 95.40% 95.47% +0.06% ========================================== Files 11 10 -1 Lines 1937 1965 +28 ========================================== + Hits 1848 1876 +28 Misses 89 89 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

karellm commented 3 months ago

I'm a bit puzzled by this use case but I don't really like the implementation.

First it looks very specific to a use case you have (not something many people would need). Second the option name skipIdenticals shouldn't remove empty values imo. That said, I don't want to make the API too complex with an extra skipEmtpy.

I actually think that the best solution here is to add hooks. We could have an hook to update the catalog before it is written to file. You could then add the logic you need in there.

What do you think?

omid commented 3 months ago

@karellm I can answer about the use case. If you have worked with gettext (i18next has gettext tag on npm) you know in gettext, you write translations like t('The Default Language Text') and mostly the default language (which is EN by default) translation file is almost empty.

We can rename the name skipIdentical to elaborate the use case. I agree, and we can have another array for skipEmpty to skip empties in some languages. On the other hand, it can be more objective, like refer to defaultLanguages.