genstrings 不适用于 NSLocalizedString 的宏
我想将“NSLocalizedString”缩短为“_”,所以我使用宏 _(x) NSLocalizedString(@x, @__FILE__)
。
但现在,当我想生成用于本地化的字符串时 <代码>查找 . -名称 \*.m | xargs genstrings 它什么也不产生。
有什么帮助吗?
I would like to shorten "NSLocalizedString" to "_" so I'm using macro_(x) NSLocalizedString(@x, @__FILE__)
.
But now, when I want to generate strings for localization withfind . -name \*.m | xargs genstrings
it generates nothing.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用“-s”参数告诉 genstrings 查找不同的函数:
但是,MyFunctionName 必须遵循与内置 NSLocalizeString 宏之一相同的命名和参数约定。
在您的情况下,您不能只指定字符串键,还必须指定文档字符串。事实上,您应该永远生成没有字符串和文档的字符串文件。在许多语言中,实际的短语或单词取决于上下文。德语就是一个很好的例子,其中一辆车是“das auto”,而不止一辆是“die autos”。还有更多的例子,包括性别、数字、时间、问题与陈述、是与否的变化。文档字符串可以帮助您的翻译人员确定要使用的翻译。
此外,最佳做法是使用与母语单词不同的键。这就是说使用 NSLocalizedStringWithDefaultValue(key, table, bundle, val, comment)。
您可以为表指定 nil,为包参数指定 [NSBundle mainBundle]。
您可以将其包装为简写,但您仍然必须遵循 StringWithDefaultValue 名称和 genstring 的参数才能工作。
我强烈建议您查看 WWDC 2012 的本地化提示和技巧会议。
莫里斯
You can tell genstrings to look for a different function by using the '-s' argument:
However, MyFunctionName must follow the same naming and argument conventions as one of the built in NSLocalizeString macros.
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.
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.
You can wrap this in a shorthand, but you still have to follow the StringWithDefaultValue name and the arguments for genstrings to work.
I strongly recommend you look at the WWDC 2012 session on Localization Tips and Tricks.
Maurice
您可以使用
genstrings
的-s
选项。来自 手册页 :所以我想你可以尝试:
You can use the
-s
option ofgenstrings
. From the man page :So I think you could try :
当我的 NSLocalizedString 宏采用 1 个参数而不是 genstrings 期望的 2 个参数时,我遇到了同样的问题,所以我编写了完成这项工作的 python 脚本。
脚本的第一个参数是宏名称,第二个参数是项目的路径。
I had the same problem when my NSLocalizedString macro was taking 1 argument instead of 2 like genstrings expects, so i wrote i python script that does the job.
the first argument for the script is the macro name and the second is the path to your project.
我改进了 Or Arbel 的脚本,以包含单行上有多个宏调用的情况:
I have improved Or Arbel's script to include the cases where there's multiple macro-calls on a single line: