如何以编程方式快速更改应用程序的可本地化字符串文件? [英] How do I change the Localizable string file of the app programatically in swift?
本文介绍了如何以编程方式快速更改应用程序的可本地化字符串文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以使用阿拉伯语和英语两种语言的应用程序. 我对每个可本地化的字符串文件制作了一个,它可以正常工作,当我更改系统语言时,应用程序的语言正在更改,但是当用户按下按钮以更改应用程序语言时,我仍然需要这样做它.
I have an app that works with two languages arabic and english. I made to Localizable string files one for each , and it is working properly, when I change the system language the language of the app is changing, but I need to do that when the user presses a button to change the application language while still inside it.
推荐答案
var localized: String {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var lang = "en"
if(appDelegate.isGreek)
{
lang = "el"
}
let path = NSBundle.mainBundle().pathForResource(lang, ofType: "lproj")
let bundle = NSBundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}
el代表希腊语言,这是String类的扩展.
Where el is for greek language and this is extension to String class.
这篇关于如何以编程方式快速更改应用程序的可本地化字符串文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文