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

前端之家收集整理的这篇文章主要介绍了使xcodebuild -exportLocalizations知道如何解析自定义NSLocalizedString宏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用内置宏:

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.

猜你在找的Xcode相关文章