NSLocalizedString not defaulting to Base language

后端 未结 4 2125
情话喂你
情话喂你 2021-02-20 09:20

I have the following problem with a small iOS 7 project on which I\'m testing the localisation capabilities.

  • I have a default project, with one VC, in which I have
4条回答
  •  离开以前
    2021-02-20 10:05

    I have an equivalent in Swift:

    public func LS(_ key: String) -> String {
        let value = NSLocalizedString(key, comment: "")
        if value != key || NSLocale.preferredLanguages.first == "en" {
            return value
        }
    
        // Fall back to en
        guard
            let path = Bundle.main.path(forResource: "en", ofType: "lproj"),
            let bundle = Bundle(path: path)
            else { return value }
        return NSLocalizedString(key, bundle: bundle, comment: "")
    }
    

提交回复
热议问题