我可以通过编程方式更改单击按钮时的Localizable.strings文件,而无需重新启动应用程序 [英] Can I programatically change the Localizable.strings file on button click with out restarting the app

查看:90
本文介绍了我可以通过编程方式更改单击按钮时的Localizable.strings文件,而无需重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用2种语言的阿拉伯语和英语的应用程序.我设法将布局更改为RTL(阿拉伯语)和普通(英语).另外,我还添加了阿拉伯语和英语的Localizable.strings文件.

I am creating an app which uses 2 languages Arabic and English. I have managed to change the layout to RTL for Arabic and normal for English. Also I have added the Localizable.strings file for Arabic and English.

该应用会选择英语,选择了英语时会显示常规布局,并且会拾取阿拉伯语,并且在应用首次启动或每次重新启动时都会显示RTL布局.

The app picks up English and normal layout shows when English is selected and picks up Arabic and RTL layout is shown when the app is started the first time or on every restart.

在运行时不会拾取阿拉伯语或英语Localizable.strings文件.有没有办法做到这一点.

It does not pick up Arabic or English Localizable.strings file on runtime. Is there a way to do this.

推荐答案

您可以更改从中读取的当前包

You can change the current bundle you read from

extension String {
      func localizedStr(language:String) -> String {
          let path = Bundle.main.path(forResource: language, ofType: "lproj")
          let bundleName = Bundle(path: path!)
          return NSLocalizedString(self, tableName: nil, bundle: bundleName!, value: "", comment: "")

    }
}

行动中

在此处查看演示本地

这篇关于我可以通过编程方式更改单击按钮时的Localizable.strings文件,而无需重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆