加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:24:03 所属栏目:百科 来源:网络整理
导读:使用内置宏: NSLocalizedStringWithDefaultValue(@"fantasy-group.group-rank.stats-label",nil,[NSBundle mainBundle],@"Group Rank",nil); 导出本地化时导致生成的.xliff文件中的以下块中的结果: trans-unit id="fantasy-group.group-rank.stats-label"
使用内置宏:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读