Adding custom language to the iOS app

北慕城南 提交于 2019-12-10 12:00:45

问题


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.

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.

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?


回答1:


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

Source is available here: https://github.com/amjaliks/ObjCAdditions/tree/master/Source/Classes



来源:https://stackoverflow.com/questions/5344906/adding-custom-language-to-the-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!