首页 > 解决方案 > 本地化 NSPredicateEditor / NSPredicateEditorRowTemplate

问题描述

我想得到什么

如何使用 NSPredicateEditorRowTemplate 进行本地化

它没有很好的记录,弄清楚它是一件非常痛苦的事情。

一切都是以编程方式编写的

我想要法语、意大利语版本等。

https://github.com/thierryH91200/THPredicateEditorSwift

标签: macoscocoalocalizationswift4nspredicateeditor

解决方案


本地化 NSPredicateEditor 比通常的本地化要复杂一些。

首先,您需要在代码中的某个地方调用 NSLocalizedString() 以便 genstrings 能够找到它们。

其次,密钥需要遵循一种特殊的格式,该格式将指示 genstrings 生成给定行的所有组合:

NSLocalizedStringFromTable(@"%[Any, All, None]@ of the following are true", @"Predicate", @"localize the compound row template")
NSLocalizedStringFromTable(@"%[property]@ %[is, is not, contains, begins with, ends with, like, matches]@ %@", @"Predicate", @"localize the string row template")
NSLocalizedStringFromTable(@"%[birthMonth]@ %[is, is not]@ %[January, February, March, April, May, June, July, August, September, October, November, December]@", @"Predicate", @"localize the selection row template")

在上面的示例中,genstrings 将查看括号之间的选项并为 Predicate.strings 文件中的所有组合生成本地化字符串。

最后,您必须通过设置formattingStringsFilename属性让您的 NSPredicateEditor 实例知道要使用哪个字符串文件。

有关更多信息,请参阅此博客文章


推荐阅读