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

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

问题描述

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

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.

有什么想法吗?

推荐答案

有更好的方法来做到这一点.您可以像这样强制使用语言:

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. 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天全站免登陆