在自动布局中处理 iOS 应用程序中的语言更改

Handle language change within iOS App in auto layout(在自动布局中处理 iOS 应用程序中的语言更改)

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

问题描述

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

从 iOS 9 开始,设计的带有自动布局的 UI 将得到妥善处理,同时更改 iPhone 设置中的语言.

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

我需要澄清一下,是否有任何解决方案可以在不重新启动应用程序的情况下更改此(应用程序内的语言)?如果否,对于重新启动应用程序,我可以显示警报并退出应用程序(使用 exit(0))吗?这将得到应用审核团队的批准吗?

解决方案

我需要澄清一下,是否有任何解决方案可以改变这一点(应用内的语言)无需重新启动应用?

是的,有!如果您已经通过检查 AppleLanguages 全局键并使用自动布局来处理更改语言,那么执行这样的功能应该很容易.

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

我建议检查使用

<小时>

另外,您可能想查看 Localize-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 应用程序中的语言更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在自动布局中处理 iOS 应用程序中的语言更改

基础教程推荐