创建本地化的iPhone应用程序,但允许用户更改应用程序的语言 [英] Creating a localized iPhone app but allowing the user to change language for the application

查看:104
本文介绍了创建本地化的iPhone应用程序,但允许用户更改应用程序的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个本地化的应用程序,一切正常。问题是我想允许用户在app settings文件夹中专门为特定应用程序选择语言。这应该是用户将他们的手机设置为一种语言(例如法语)以将应用程序设置为英语。

I'm working on a localized app and everything is working fine. The problem is I want to allow the user to specifically select the lenguage for the specific app, in the app settings folder. This should users that their phone is set to one language (e.g. french) to set the app to work in English.

我目前正在使用NSLocalizedString获取本地化字符串但是通过查看宏的所有变体,我找不到一个可以让我指定语言的内容。

I'm currently using NSLocalizedString to get localized string but looking through all variation of the macro I can't find one that will let me specify the language.

关于如何做的任何想法?

Any ideas on how to do it?

推荐答案

有一种更好的方法可以做到这一点。您可以像这样强制语言:

There is a better way to do this. You can force the language like so:

[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];

并通过以下方式撤消此设置:

And undo this setting by:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];

NB。您通常必须重新启动应用程序才能生效。

NB. you will normally have to restart the app for this to take affect.

考虑是否需要调用 [[NSUserDefaults standardUserDefaults] synchronize];

我同意不需要允许用户指定语言。但是,一个例外是能够覆盖语言并将其设置为开发人员的母语。如果用户可以说出开发人员的语言(例如英语),那么如果翻译不正确,他们可能希望使用该语言的应用程序。

I agree there is little need to allow the user to specify a language. However the one exception is being able to override the language and set it to the developer's native language. If the user can speak the developer's language (e.g. English for me) then they may wish to use the App in that language, if the translations are incorrect.

我引用了这个回答:如何强制NSLocalizedString使用特定的语言(答案实际上并不适用于我,但遵循评论中的想法。我解决了这些问题。

I reference this answer: How to force NSLocalizedString to use a specific language (the answer doesn't actually work for me, but following the ideas in the comments did. The undo stuff I worked out.

这篇关于创建本地化的iPhone应用程序,但允许用户更改应用程序的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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