iPhone 上国家/地区名称显示不正确

问题描述 投票:0回答:1

iOS从17.1.2更新到17.4.1后,TableView中部分国家的显示发生了变化,例如台湾变成了Root(Taiwn),澳门也变成了Root(Makao),香港和中国也一样。代码一年多来没有更改且正常工作。

 private func createCountriesByLang(lang: Langs) -> [CountryModel] {
        var result = [CountryModel]()
        for code in NSLocale.isoCountryCodes {
            let id = NSLocale.localeIdentifier(fromComponents: [NSLocale.Key.countryCode.rawValue: code])
            let name = NSLocale(localeIdentifier: lang.rawValue).displayName(forKey: NSLocale.Key.identifier, value: id) ?? "Country not found for code: \(code)"
            result.append(CountryModel(name: name, code: code))
        }
        switch lang {
        case Langs.en:
            result.append(CountryModel(name: "Zaire", code: "ZR"))
            result.append(CountryModel(name: "British Indian Ocean Territory", code: "IO"))
            result.append(CountryModel(name: "Netherlands Antilles", code: "AN"))
        case Langs.ru:
            result.append(CountryModel(name: "Заир", code: "ZR"))
            result.append(CountryModel(name: "Британская Территория в Индийском Океане", code: "IO"))
            result.append(CountryModel(name: "Нидерландские Антильские о-ва", code: "AN"))
        case Langs.zh:
            result.append(CountryModel(name: "扎伊尔", code: "ZR"))
            result.append(CountryModel(name: "英属印度洋领地", code: "IO"))
            result.append(CountryModel(name: "荷属安的列斯", code: "AN"))
        }
        return result
    }
swift xcode localization
1个回答
0
投票

尝试使用而不是displayName

let name = NSLocale(localeIdentifier: lang.rawValue).localizedString(forCountryCode: code)
© www.soinside.com 2019 - 2024. All rights reserved.