在iOS中本地化字符串:默认(后备)语言? [英] Localizing strings in iOS: default (fallback) language?
问题描述
当应用程序不支持设备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语言设置为的设备上运行应用程序意大利语
该应用将使用密钥字符串 POWER_TO_THE_PEOPLE_BTN
和 POWER_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.
来自上面的例子应该很清楚,使用英文字符串作为键是行不通的。
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.
重要: as @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屋!