fnando / i18n

A small library to provide the I18n translations on the JavaScript.
https://fnando.github.io/i18n/
MIT License
169 stars 20 forks source link

Feature Request: Improve I18n pluralize method #100

Open eugenet8k opened 3 months ago

eugenet8k commented 3 months ago

Description

Derived from the bug https://github.com/fnando/i18n/issues/99. If I wanted to patch current I18n.pluralize behavior by overriding pluralize method, it wouldn't work. This is because i18n class has code duplication and it does not uses a single point of entry into pluralizer

Describe the solution

To update lines

https://github.com/fnando/i18n/blob/f49c86d905928d89c3e6bb0265038274be1e92c9/src/I18n.ts#L383-L389

to something like

translation = this.pluralize({ 
   count: options.count || 0, 
   scope: translation as unknown as string, 
   options, 
   baseScope: getFullScope(this, scope, options), 
 }); 

in this case the overrides pluralize will be respected count based translations.