marmelroy / Localize-Swift

Swift friendly localization and i18n with in-app language switching
MIT License
3.08k stars 330 forks source link

Pluralization don't work (explanation) #138

Open NikKovIos opened 5 years ago

NikKovIos commented 5 years ago

Since pluralization use String class function localizedStringWithFormat which

Returns a string created by using a given format string as a template into which the remaining argument values are substituted according to the user’s default locale.

..so it takes user’s default locale. For example if you have the device with English, but in app choose Russian, it will take the plural type for English, but plural string for Russian. We know, that for English used only one and other types. For Russian used all (one, two, few, many..). But the app, in that case, will return only one and other for Russian.

It goest to a correct .stringsdict file, but ignores plural categories, which are not used in device's current language.

The problem is because when changing language in app, we substitute bundle and then use this bundle to take localized string. But in order to use pluralization we need to use only one available function for this: localizedStringWithFormat. And it uses the device localization.

It seems that it's a bug because String.localizedStringWithFormat always use categories for current device language even if UserDefaults.standard added a recent key for AppleLanguages.


Workaround: Is to use custom implementation of pluralization.

NikKovIos commented 5 years ago

It seems that here is a woking solution for pluralization https://github.com/andresilvagomez/Localize. Didn't test yet.