问题描述
是否可以使用NSLocalizedString基础结构(基于localizable.strings)和自定义的本地化?
Is it possible to use the NSLocalizedString infrastructure (based on localizable.strings) with a custom-defined "localization"?
事情是,有一些语言对男性和女性有不同的措辞。我想在首次启动时询问用户的性别,然后使用相应的短语。当然,两者都基于相同的语言。我可以使用自己的代码来完成它,但如果可能的话,我宁愿这么做。
The thing is, there are some languages that have different wordings for males and females. I want to ask the user's gender on first launch and then use the appropriate phrases. Of course, both are based on the same language. I can do it with my own code but I'd rather do it the easy way if possible.
推荐答案
NSLocalizedString只是一个在NSBundle.h中定义的宏
重新定义它或创建一个新的,例如NSGenderAwareLocalizedString以满足您的需求。
NSLocalizedString is just a macro defined in NSBundle.h
Redefine it or create a new one, for example NSGenderAwareLocalizedString to fit your needs.
使用新的宏,你可以自由地做任何你想要的事情:每种语言两个字符串文件,一个用于男性,一个用于女性。或者,您可以定义一个约定,以便从男性本地化字符串的键中为女性的本地化字符串派生键。
With the new macro, you are free to do whatever you want: two strings files per language, one for male and one for female. Or you can define a convention to derivate the key for a localized string for a female from the key of the male localized string.
这篇关于自定义NSLocalizedString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!