IOS Swift Localisation Plural : compatibility with 14.4.2

188 Views Asked by At

As an IOS developer, I would like to develop the localisation module which supports different language by user default.

When it runs with 12.4, 13.4, 14.4, it works

When it runs with 14.4.2, it does not work.

Would you please tell us more reminding details so that plural localisation works on 14.4.2 too? X

Below is my working. Thank you in advance.

Swift Code:

let value: Int = 1     
"diff_room".localizedForPlural(Int(value))

localizedForPlural method:

 func localizedForPlural(_ value: Int) -> String  {
        let selectedLanguage =  Localize.currentLanguage()
        //recover the language chosen by the user (in my case, from UserDefaults)
        if let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj") , let selectedBundle = Bundle(path: path) {
            let string = NSLocalizedString(self, tableName: nil, bundle: selectedBundle, value: value.stringValue(), comment: "")
            DLog("#930 current language A: \(Localize.currentLanguage()) :\(String(format: string , value))")
            return String(format: string , value)
        }
        DLog("#930 current language B: \(Localize.currentLanguage()) :\(localizedPlural(value))")
        return localizedPlural(value)
    }

Localizable.stringDict

<key>diff_room</key>
<dict>
    <key>NSStringLocalizedFormatKey</key>
    <string>%#@diff_room@</string>
    <key>diff_room</key>
    <dict>
        <key>NSStringFormatSpecTypeKey</key>
        <string>NSStringPluralRuleType</string>
        <key>NSStringFormatValueTypeKey</key>
        <string>d</string>
        <key>one</key>
        <string>%d Room</string>
        <key>other</key>
        <string>%d Rooms</string>
    </dict>
</dict>

File Structure :

File

Updates:

Below display my screenshots for applying plural localisations diff_room is the key I am going to apply for Rooms

Capscreen - IOS 12 mini 14.4

Capscreen - IOS 12 mini. 14.4.2

enter image description here

0

There are 0 best solutions below