我只是坚持本地化内部framworks.任何人都可以帮助我从应用程序本身的内部框架本地化,如UIKit等,而无需重新启动.我的代码工作正常,但对于内部框架的情况需要重新启动.只是内部框架没有得到本地化.
我目前的代码是:
创建一个名为BundleExtension.swift的文件,并将以下代码添加到其中 –
var bundleKey: UInt8 = 0class AnyLanguageBundle: Bundle {overrIDe func localizedString(forKey key: String,value: String?,table tablename: String?) -> String { guard let path = objc_getAssociatedobject(self,&bundleKey) as? String,let bundle = Bundle(path: path) else { return super.localizedString(forKey: key,value: value,table: tablename) } return bundle.localizedString(forKey: key,table: tablename) }}extension Bundle {class func setLanguage(_ language: String) { defer { object_setClass(Bundle.main,AnyLanguageBundle.self) } objc_setAssociatedobject(Bundle.main,&bundleKey,Bundle.main.path(forResource: language,ofType: "lproj"),.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }}
现在,无论何时需要更改语言,都可以调用此方法:
func languagebuttonAction() { // This is done so that network calls Now have the Accept-Language as "hi" (Using Alamofire) Check if you can remove these UserDefaults.standard.set(["hi"],forKey: "AppleLanguages") UserDefaults.standard.synchronize() // Update the language by swaPing bundle Bundle.setLanguage("hi") // Done to reintantiate the storyboards instantly let storyboard = UIStoryboard.init(name: "Main",bundle: nil) UIApplication.shared.keyWindow?.rootVIEwController = storyboard.instantiateInitialVIEwController()}解决方法 查看此演示,它将适合您.
Link
总结以上是内存溢出为你收集整理的ios – 强制本地化内部框架,如UIKit,无需重启App全部内容,希望文章能够帮你解决ios – 强制本地化内部框架,如UIKit,无需重启App所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)