将自定义语言添加到iOS应用 [英] Adding custom language to the iOS app

查看:86
本文介绍了将自定义语言添加到iOS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在支持语言之间添加自定义语言(iOS没有本地化).用户可以在应用设置中选择所需的语言(内置屏幕,在设置"应用中为否).我将其存储到NSUserDefaults:

I need to add a custom language (iOS has no localisation for it) among with support languages. A user is able to choose desired language in app settings (built-in screen, no in Settings app). I store it to NSUserDefaults:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"lv"] forKey:@"AppleLanguages"];

下次,当应用启动时,它将以选定的语言加载.而且效果很好.

Next time, when the app starts, it loads with selected language. And works great.

但这是一个小"问题.该应用程序需要重新启动.因此,我需要一种退出应用程序的方法.

But here is a 'small' issue. The app needs to be restarted. Thus, I need a way to quit the app.

我不想将UIApplicationExitsOnSuspend添加到Info.plist,因为通常用户不会切换语言,因此,我希望应用程序通常会在后台运行并在用户返回时恢复运行.

I don't want to add UIApplicationExitsOnSuspend to Info.plist, because usually the user won't switch languages, thus, I want the app typically goes to background and resumes, when a user comes back.

我知道,不允许我使用exit()终止该进程.因此,我想也许可以在运行时设置UIApplicationExitsOnSuspend吗?场景将与此类似: 用户设置所需的语言并进行确认. 该应用程序设置UIApplicationExitsOnSuspend(或执行类似操作). 该应用程序指示用户通过按主页"按钮退出该应用程序.

I know, I am not allowed to kill the process with exit(). Thus, I imagine maybe it is possible to set UIApplicationExitsOnSuspend at runtime? Scenarios will be similar to this: A user sets desired language and confirms it. The app sets UIApplicationExitsOnSuspend (or do something similar to it). The app instructs a user to quit the app by pressing Home button.

当然,我可以通过终止进程来指示用户退出应用程序(转到主屏幕,双击主页"按钮,点击并按住一个应用程序图标,点击减号).但这看起来很烦人.

Of course, I may instruct a user to quit the app, by killing the process (go to Home screen, double click Home button, tap and hold an app icon, tap the minus). But it looks to complicated and annoying.

也许您还有其他建议,如何在应用中添加切换语言的功能?

Maybe you have another suggestions, how to add to an app ability to switch languages?

推荐答案

我已经实现了自己的字符串捆绑,从而实现了应用内语言切换.

I have achieve in-app language switch by implementing my own string bundle.

可在此处找到源: https://github.com/amjaliks/ObjCAdditions /tree/master/Source/Classes

这篇关于将自定义语言添加到iOS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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