使xcodebuild -exportLocalizations知道如何解析自定义NSLocalizedString宏

使xcodebuild -exportLocalizations知道如何解析自定义NSLocalizedString宏,第1张

概述使用内置宏: NSLocalizedStringWithDefaultValue(@"fantasy-group.group-rank.stats-label", nil, [NSBundle mainBundle], @"Group Rank", nil); 导出本地化时导致生成的.xliff文件中的以下块中的结果: <trans-unit id="fantasy-group.group-ran 使用内置宏:

NSLocalizedStringWithDefaultValue(@"fantasy-group.group-rank.stats-label",nil,[NSBundle mainBundle],@"Group Rank",nil);

导出本地化时导致生成的.xliff文件中的以下块中的结果:

<trans-unit ID="fantasy-group.group-rank.stats-label">    <source>Group Rank</source>    <note>No comment provIDed by engineer.</note>  </trans-unit>

这从source开始按预期工作:

The main advantage to these macros is that they can be parsed by the
genstrings tool and used to create your application’s strings files.

但是如果我尝试使用我自己的宏来避免指定表和bundle,并且可能在split up the string file中指定我自己的表:

#define WsllocalizedString(key,val,comment) \[[NSBundle mainBundle] localizedStringForKey:(key) value:(val) table:nil][WsllocalizedString(@"fantasy-group.group-rank.stats-label",nil);

当我尝试生成xliff文件时,XCode或关联的命令行工具无法获取它:

$xcodebuild -exportLocalizations -localizationPath WSL/Translations/ -project WSL.xcodeproj

如果我只是在做genstrings,我可以做以下source:

find . -name *.m | xargs genstrings -o en.lproj -s WsllocalizedString

但我想要xliffs.有没有一个参数我可以传递给xcodebuild来保持这个梦想活着?

解决方法 不确定Objective-C,但我通过重新定义NSLocalizedString函数为Swift做了这个:

public func NSLocalizedString(key: String,tablename: String? = nil,bundle: NSBundle = NSBundle.mainBundle(),value: String = "",comment: String) -> String{    return yourBundleHere.localizedStringForKey(key,value: value,table: tablename)}

在我的情况下,我需要使用自定义NSBundle.

总结

以上是内存溢出为你收集整理的使xcodebuild -exportLocalizations知道如何解析自定义NSLocalizedString宏全部内容,希望文章能够帮你解决使xcodebuild -exportLocalizations知道如何解析自定义NSLocalizedString宏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1005301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存