swift 这将英语转换为任何其他语言。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 这将英语转换为任何其他语言。相关的知识,希望对你有一定的参考价值。
extension String {
var localized: String {
if let language = UserDefaults.standard.object(forKey: "AppleLanguages") as? String {
switch language {
case "en" :
guard let path = Bundle.main.path(forResource: "en", ofType: "lproj") else { return NSLocalizedString(self, comment: self) }
guard let bundle = Bundle(path: path) else { return NSLocalizedString(self, comment: self) }
return NSLocalizedString(self, tableName: nil, bundle: bundle, value: "", comment: self)
case "fr" :
guard let path = Bundle.main.path(forResource: "fr", ofType: "lproj") else { return NSLocalizedString(self, comment: self) }
guard let bundle = Bundle(path: path) else { return NSLocalizedString(self, comment: self) }
return NSLocalizedString(self, tableName: nil, bundle: bundle, value: "", comment: self)
default :
return NSLocalizedString(self, comment: self)
}
} else {
return NSLocalizedString(self, comment: self)
}
}
}
以上是关于swift 这将英语转换为任何其他语言。的主要内容,如果未能解决你的问题,请参考以下文章