A Problem with Plural Localization

I have a function to get the localized string for plural cases.

extension String
   static func localizedStringForPlurals(
      formatKey key: String,
      comment: String = "",
      args: CVarArg... ) -> String
   {
     let format = NSLocalizedString(key, comment: comment)
     var result = withVaList(args){
        (NSString(format: format, 
         locale: NSLocale.current,
         arguments: $0) as String)
     }
     return result
   }
}

The key point is NSLocalizedString to get localized string for plural case from dict file.

I have an example of getting localized string for taps. If the int number is one, the localized string is "This tap"; if int is larger than one, i.e., others, the string is "These taps". See attachment dict file (English).

It works fine for English. For example:

var count: Int
...
let locS = String.localizedStringForPlurals(

            formatKey: "theseTaps", args: count) // "This tap" if count is 1 // "These taps" if count is > 1

However, it does not work well for Chinese. Here is the similar dict file for Chinese.

The result in Swift code is always plural string, i.e., "These tap", even count is 1.

I am not sure if this is a bug in NSLocalizedString or not. I know that in Chinese in general there are no plural cases. However, as in this example, there are plural cases, this tap or these tap. In Chinese there is no plural for "tap", but "this", and "these" in Chinese are different, and they are plural cases.

Any way to resolve the issue? I do like Apple's localization for plural framework. I would like this framework works as developer's expectation, as in my example in two dict files.

Hi,

StringsDict currently only supports number-based plural rules:

String(localized: "\(count) tap(s) has/have been registered.", comment: "Label, 1+ tap(s) got saved") // read in .stringsdict

 

“This tap”, “These taps”, “Both taps”, etc. obey to different plural rules so you would not use StringsDict but instead 2 strings determined by an if:

let text: String
if count == 1 {
    text = String(localized: "This tap has been registered.", comment: "Label, 1 finger tap got saved") // read in .strings
} else {
    text = String(localized: "These taps have been registered.", comment: "Label, multiple finger taps got saved") // read in .strings
}

 

You’ll always see the other StringsDict case used in Chinese since it doesn’t have plural for enumerations (“number-based plurals”: 42 tap(s)). But Chinese does have plurals for denomination (“plurals without a number”: this tap).

Similarly, since one is used in Russian for 1, 21, 31…, using a StringsDict for This tap would show it (singular) for 1, 21, 31… instead of just 1.

So for these 2 reasons, you need to use an if/else and not Stringsdict.

A Problem with Plural Localization
 
 
Q