自定义 NSLocalizedString? [英] Custom NSLocalizedString?
问题描述
是否可以将 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!