I'm using i18next
with React
.
I have some translations like these:
t('FIELD_MAX_LENGTH', {maxLength: 255}) // 90% <br/>
t('FIELD_MAX_LENGTH', {maxLength: 100}) // 5% <br/>
t('FIELD_MAX_LENGTH', {maxLength: 32}) // 5% <br/>
Since the value of maxLength
is 255 most of the time, so I prefer to make it the default value for all translations, so my code can be like this:
t('FIELD_MAX_LENGTH') // maxLength will be 255 by default <br/>
t('FIELD_MAX_LENGTH', {maxLength: 100}) <br/>
t('FIELD_MAX_LENGTH', {maxLength: 32}) <br/>
Is this possible for i18next
, if yes how to do it?
Thank guys.
Yes, you can define defaultVariables in the interpolation options, like this:
i18next.init({
// ... your current options
interpolation: {
defaultVariables: { maxLength: 255 }
}
})