i18next-parser
i18next-parser copied to clipboard
Detect Reused Keys
🚀 Feature Proposal
Allow detect key reuse and option to warn or fail on reuse.
Example: dev writes t('foobar')
in two different files ultimately writing translations to the same JSON.
With config warnOnDuplicates: true
, parser would log something like, Key 'foobar' is reused 2 times.
With config failOnWarnings
, this situation would cause an exit 1.
I believe this can be accomplished via an option
and conflict
type added here.
Motivation
Accidental key reuse results in wrong translations. The parser should be able to detect and prevent this scenario. It happens especially in cases where the key is used as default value.
For example, t('Cancel')
in one place might mean "Decide not to submit a form", while in another place, it might mean "End your subscription". Forcing developers to use unique keys prevents accidental mistranslations.
Example
// Foo.js
t('Foobar')
// Bar.js
t('Foobar')
=> 'Warning: key 'Foobar' is reused 2 times.'
A warning is thrown if there is a key use twice with a conflict on the value. What you are proposition is not yet implemented though.