本文介绍了NSLocalizedString显示原始密钥,而不是从其他语言加载字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当当前语言的键丢失时,我无法使用NSLocalizedString(key, comment: "")从Localizable.strings中加载字符串. NSLocalizedString返回原始密钥

I'm having trouble using NSLocalizedString(key, comment: "") to load strings from Localizable.strings when the key is missing for the current language. NSLocalizedString returns a raw key

例如,当存在用于英语本地化的字符串而对于俄语则缺少该字符串时:

For instance, when string is present for English localization, but is missing for Russian:

"config.updating" = "Update in progress...";

当iOS语言设置为俄语时,调用NSLocalizedString返回"config.updating"

Calling NSLocalizedString when iOS language set to Russian returns "config.updating"

NSLocalizedString("config.updating", comment: "") // "config.updating"

NSLocalizedString是否应该访问NSUserDefaults中的"AppleLanguages"键来确定用户的设置并选择其他字符串?

Shouldn't NSLocalizedString access the "AppleLanguages" key in NSUserDefaults to determine what the user's settings are and pick some other string?

推荐答案

否,文档对于NSLocalizedString(key,comment)非常清楚-

您还希望它返回什么?该代码只是在字典中查找键.它不知道该密钥与什么消息相关联,更不用说如何将该消息翻译成俄语了.

What else would you expect it to return? The code simply looks up the key in a dictionary. It has no idea what message is associated with the key, let alone how to translate that message into Russian.

这篇关于NSLocalizedString显示原始密钥,而不是从其他语言加载字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:25