问题描述
我想将"NSLocalizedString"缩短为"_",所以我正在使用宏 _(x)NSLocalizedString(@x,@__ FILE __)
I would like to shorten "NSLocalizedString" to "_" so I'm using macro_(x) NSLocalizedString(@x, @__FILE__)
.
但是现在,当我想生成用于本地化的字符串时, find.名称\ *.m |xargs genstrings
它什么也不会产生.
But now, when I want to generate strings for localization withfind . -name \*.m | xargs genstrings
it generates nothing.
有帮助吗?
推荐答案
您可以使用'-s'参数告诉genstrings寻找不同的函数:
You can tell genstrings to look for a different function by using the '-s' argument:
genstring -s MyFunctionName ....
但是,MyFunctionName必须遵循与内置NSLocalizeString宏之一相同的命名和参数约定.
However, MyFunctionName must follow the same naming and argument conventions as one of the built in NSLocalizeString macros.
在您的情况下,您不仅可以指定字符串键,还必须指定文档字符串.实际上,您应该从不不生成既不包含字符串也不包含文档的字符串文件.在许多语言中,实际的短语或单词将取决于上下文.德语是一个很好的例子,其中汽车是"das auto",而不是"die autos".还有更多示例,包括性别,数字,时间,问题与陈述的变化以及是与否的变化.文档字符串可帮助您的翻译确定要使用的翻译.
In your case, you can not just specify the string key, you must also specify the documentation string. In fact, you should never generate a strings file without both the string and documentation. There are many languages where the actual phrase or word will depend on context. German is a great example where a car is "das auto" and more than one is "die autos". There are many more examples that include changes for gender, number, time, question versus statement, and yes versus no. The documentation string helps your translator figure out what translation to use.
此外,最佳做法是使用与母语单词不同的键.那就是说使用NSLocalizedStringWithDefaultValue(key,table,bundle,val,comment).您可以为表指定nil,为bundle参数指定[NSBundle mainBundle].
In addition, the best practice is to use a key that is different from the native language word. That says use NSLocalizedStringWithDefaultValue(key, table, bundle, val, comment).You can specify nil for the table and [NSBundle mainBundle] for the bundle argument.
您可以将其包装为简写形式,但是您仍然必须遵循StringWithDefaultValue名称和genstrings的参数.
You can wrap this in a shorthand, but you still have to follow the StringWithDefaultValue name and the arguments for genstrings to work.
我强烈建议您观看WWDC 2012上有关本地化技巧和窍门的会议.
I strongly recommend you look at the WWDC 2012 session on Localization Tips and Tricks.
莫里斯
这篇关于genstrings不适用于NSLocalizedString的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!