在自动布局中处理iOS App中的语言更改 [英] Handle language change within iOS App in auto layout

查看:154
本文介绍了在自动布局中处理iOS App中的语言更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们必须支持英语和阿拉伯语,但语言更改选项在应用程序本身中可用。之前我们已经处理了从右到左的语言和从左到右的语言更改代码。



从iOS 9开始,设计具有自动布局的UI将被正确处理,同时更改iPhone设置中的语言。



根据我的要求,我们更改了应用程序中的语言并直接更新了AppleLanguages键。但故事板没有正确更新。一旦我强行退出应用程序并重新启动它,它就可以正常工作。



我需要澄清一下,
是否有任何解决方案可以改变它(语言中的语言)应用程序)没有重新启动应用程序?
如果否,为了重新启动应用程序,我可以显示警报并退出应用程序(使用exit(0))吗?这是否会被应用审核小组批准?

解决方案


我需要澄清一下,有没有解决方案更改此
(应用程序内的语言)而无需重新启动应用程序?


是的,有!如果您已经通过检查 AppleLanguages 全局密钥并使用自动布局来更改语言,则应该很容易实现这样的功能。



解决方案是切换 lproj 软件包以便在不重新启动应用程序的情况下进行本地化,您应该执行 Method Swizzling 来实现它。



我建议检查使用






此外,您可能需要查看本地化-Swift 库(实际上,我没有使用它)。



希望这有帮助。


In our app, we have to support English and Arabic languages but the language changing option is available within the app itself. Earlier we have handled the right to left and left to right language changes in code.

From iOS 9 onwards, designed the UI with auto layout will be handled this properly, while changing the language in iPhone settings.

As per my requirement, we have changed the language within the app and updated the "AppleLanguages" key directly. But the storyboard is not updating properly. Once I force quit the app and relaunch it, then it working fine.

I need clarifications in that, Is there any solution to change this (language within the app) without restarting the app? If No, for restarting the app, Can I show an Alert and quit the app (by using exit(0))? Is this will approved by app review team?

解决方案

I need clarifications in that, Is there any solution to change this (language within the app) without restarting the app?

Yes, there is! if you are already handled changing the language by checking AppleLanguages global key and using Auto Layout, it should be easy to do such a functionality.

The solution would be switching the lproj bundle in order to get it localized without restarting the app, you should do Method Swizzling to achieve it.

I'd recommend to check Working with Internationalization and Localization in swift article, it will guides you clearly to do it from scratch (It works fine for me). After following along with it, the output should be similar to:


Also, you might want to check Localize-Swift library (Actually, I didn't use it).

Hope this helped.

这篇关于在自动布局中处理iOS App中的语言更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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