i18next-scanner
i18next-scanner copied to clipboard
Trans component does not respect the defaultValue
Version
- i18next: 11.6.0
- i18next-scanner: 2.6.5
Configuration
{
debug: true,
sort: true,
func: {
list: ['i18next.t', 'i18n.t', 't'],
extensions: ['.js', '.jsx']
},
trans: {
component: 'Trans',
extensions: ['.js', '.jsx'],
defaultsKey: "-",
fallbackKey: true,
},
removeUnusedKeys: true,
lngs: ['en-us', 'sv-se'],
defaultLng: 'en-us',
defaultValue: function (lng, ns, key) {
if (lng === 'en-us') {
return key; // key as value for en-us
}
return ''; // empty for the rest
},
resource: {
loadPath: 'src/locales/{{lng}}/{{ns}}.json',
savePath: 'src/locales/{{lng}}/{{ns}}.json',
},
nsSeparator: false,
keySeparator: false,
interpolation: {
prefix: '{{',
suffix: '}}'
}
}
Expected: to get an empty string in all languages other than English Result: the same english string is used in all languages
Here is a PR #103 where I 've added a failing test for this case.
IMHO there should be separate option for Trans. E.g. I am not using natural keys and that means that defaultValue for t is preferred but defaultValue for Trans is not. If I were using natural keys I would like your desired behavior.
Any news on this? I also think the defaultValue should be respected. If not any language will have a default value which is wrong (the english one) instead of the desired. Also, the fallbackKey
option should only affect key, not values.
I would be available to propose a PR but I need some guidance through the code, or at least to know where to look at.
Are there any updates for this?
I also have not succeeded in getting an empty defaultValue
for languages other than English (or whatever the source language is set to). I've tried multiple ways, even using a customTransform
, to no avail...