gpt4 book ai didi

macos - 为什么 NSPredicateEditor 会自动本地化一些表达式字符串?如何禁用?

转载 作者:行者123 更新时间:2023-12-03 17:09:39 24 4
gpt4 key购买 nike

我发现一些 NSPredicateEditor/NSPredicateEditorRowTemplate 值正在由 OS X 自动本地化。

这在运算符 .equalTo 到字符串 is 的映射中很容易观察到。

但我刚刚注意到 UTI 字符串被映射到该 UTI 的人类可读版本。

下面,我设置了“public.image”,但它随后显示为“image”

UTI operators in NSPredicateEditor

func setupPredicateEditor() {
let left = [NSExpression(forKeyPath: "Type")]

let operators = [NSComparisonPredicate.Operator.equalTo.rawValue as NSNumber]

let right = [
NSExpression(forConstantValue: "public.image"),
NSExpression(forConstantValue: "public.text"),
NSExpression(forConstantValue: "public.fakeUTI"),
];

let rowTemplate = NSPredicateEditorRowTemplate.init(leftExpressions: left, rightExpressions: right, modifier: .all, operators: operators, options: 0)
predicateEditor.rowTemplates = [rowTemplate]

predicateEditor.addRow(self)
}

只有某些有效的 UTI 才会以这种方式映射。我不知道 Operators 和 UTI 之外的其他格式是否具有自动本地化字符串。

这是一个问题,因为我想 localize my NSPredicateEditor and Row Templates .

本地化谓词的过程涉及将键与本地化值相匹配。

KEY: "%[left]@ %[is]@ %[right]@"
VAL: "%1$[left_display_string]@ %2$[is]@ %3$[right_display_string]@"

问题是键中的值必须与 UI 中显示的字符串相匹配。不是最初设置为行模板左右表达式的字符串。

因此,我无法在 key 中使用 "public.image" 进行本地化。由于某种原因,UI已经将其本地化为“image”。如果我想本地化行模板,我必须使用字符串 "image"。我不知道如何或为何选择这个 "image" 字符串。

我可以通过测试确定这些字符串,然后编写一个将表达式映射到本地化字符串的表。但我更希望有一个禁用此自动本地化的解决方案,这样我就不必担心我尚未测试的字符串。

为什么 UTI 会自动本地化?其他值是否得到相同的处理?

有没有办法禁用 UTI 字符串和/或整个谓词编辑器的自动本地化?

最佳答案

不是答案,而是一些信息:NSPredicateEditorRowTemplate 翻译 _displayValueForConstantValue: 中的字符串。它使用字典:

{
"com.apple.application" = application;
"com.apple.pict" = PICT;
"com.apple.protected-mpeg-4-audio" = "purchased music";
"com.apple.rtfd" = RTFD;
"com.compuserve.gif" = GIF;
"com.microsoft.bmp" = BMP;
"public.audio" = music;
"public.folder" = folder;
"public.html" = HTML;
"public.image" = image;
"public.jpeg" = JPEG;
"public.jpeg-2000" = "JPEG 2000";
"public.mp3" = MP3;
"public.mpeg-4-audio" = "MPEG4 audio";
"public.png" = PNG;
"public.rtf" = RTF;
"public.source-code" = "source code";
"public.text" = text;
"public.tiff" = TIFF;
"public.xml" = XML;
}

BT:

AppKit`-[NSPredicateEditorRowTemplate _displayValueForConstantValue:] + 913
AppKit`-[NSPredicateEditorRowTemplate _viewFromExpressions:] + 589
AppKit`-[NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressions:modifier:operators:options:] + 205

编辑:

_displayValueForKeyPath: 使用此字典:

{
kMDItemContentCreationDate = Created;
kMDItemContentModificationDate = "Last modified";
kMDItemContentTypeTree = "File type";
kMDItemDisplayName = "File display name";
kMDItemFSContentChangeDate = "Change date";
kMDItemFSCreationDate = "Creation date";
kMDItemFSName = "File name";
kMDItemFSOwnerGroupID = "Owner group id";
kMDItemFSOwnerUserID = "Owner user ID";
kMDItemFSSize = "File size";
kMDItemLastUsedDate = "Last opened";
kMDItemPath = "File path";
}

_displayValueForPredicateOperator:_displayValueForCompoundPredicateType: 将枚举转换为字符串。

这应该被记录下来,但事实并非如此。我在 _displayValueForConstantValue: 上放置了一个断点,然后观察发生了什么。这些词典是硬编码的,在其他版本的 macOS 中可能有所不同。

关于macos - 为什么 NSPredicateEditor 会自动本地化一些表达式字符串?如何禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42063625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com