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 这将英语转换为任何其他语言。的主要内容,如果未能解决你的问题,请参考以下文章
如何将M维数组转换为N维数组?
怎么把网页英语转化为这个中文
如何本地化系统警报
是否有将美国英语(en_US)转换为英国英语(en_GB)的API? [关闭]
使用 dot net 或任何其他语言在内存中进行 ghostscript 转换
mingw g ++以错误的语言发出警告(德语而不是英语)