在 iOS 中本地化字符串:默认(后备)语言? [英] Localizing strings in iOS: default (fallback) language?

查看:16
本文介绍了在 iOS 中本地化字符串:默认(后备)语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用不支持设备 UI 语言时,是否可以设置默认语言?

Is there a way to set a default language to be used when the device UI language is not supported by an app?

示例:我的应用已本地化为英语和德语:

Example: My app is localized into English and German:

// en.lproj:
"POWER_TO_THE_PEOPLE_BTN" = "Power";
"POWER_PLUG_BTN" = "Power";

// de.lproj:
"POWER_TO_THE_PEOPLE_BTN"  = "Macht";
"POWER_PLUG_BTN" = "Spannung";

现在,如果我在 UI 语言设置为 Italian 的设备上运行应用程序,应用程序将使用键字符串 POWER_TO_THE_PEOPLE_BTNPOWER_PLUG_BTN.

Now, if I run the app on a device with UI language set to Italian the app will use the key strings POWER_TO_THE_PEOPLE_BTN and POWER_PLUG_BTN.

在这种情况下,必须有一种方法可以指定应用程序使用的默认(备用)语言.

There must be a way to specify a default (fallback) language to be used by the application in such a case.

从上面的例子可以看出,使用英文字符串作为key是行不通的.

From the above example it should be clear that using the English string as a key will not work.

我现在看到的唯一选择是使用 NSLocalizedStringWithDefaultValue 而不是 NSLocalizedString.

The only option I see right now is to use NSLocalizedStringWithDefaultValue instead of NSLocalizedString.

推荐答案

也许这应该有帮助?-- iPhone:本地化/国际化默认字符串文件

Perhaps this should help? -- iPhone: localization / internationalization default strings file

默认情况下它应该回退到英语.我刚刚将我的手机切换到我的应用程序未本地化的语言,并且文本都是英文的,正如预期的那样.

It should fallback to English by default. I've just switched my phone to a language into which my app is not localized, and the text was all in English, as expected.

重要提示: 正如@hyperspasm 评论的那样:为了扩展/改写这一点,后备语言是用户最近在设备设置中选择的语言,它也在应用程序的捆绑.

Important: as @hyperspasm commented : To expand on/rephrase this, the fallback language is the language which was most recently chosen by the user in the device Settings, that is also represented in the app's bundle.

这篇关于在 iOS 中本地化字符串:默认(后备)语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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