我有一个包含自定义Obj-C操作的OSX Automator工作流程。它有效,但我无法对其进行本地化。我的测试行动是:
- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo
{
NSArray *contactStrings = (NSArray *)input;
NSString *name = contactStrings[0];
NSString *address = contactStrings[1];
NSString *comment = NSLocalizedString(@"IMPORTED", nil);
NSString *output = [NSString stringWithFormat:@"Name: %@, Address: %@, Comment: %@", name, address, comment];
return output;
}
我有一个带有基础和德语本地化的本地化Localizable.strings
文件
基地(没有评论):
"IMPORTED" = "Imported from OSX service";
德语(没有评论):
"IMPORTED" = "Über OSX-Dienst eingelesen";
问题在于,当执行Automator脚本时,注释字符串将输出为IMPORTED
,例如本地化根本不起作用。
可能是什么原因?
答案 0 :(得分:0)
我解决了这个问题:
NSLocalizedString(...)
是NSBundle.h
中定义为
#define NSLocalizedString(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
这意味着通过使用此宏,在Automator应用程序的主要包中搜索{strong> ,而不是Obj-c操作的包> !这也记录在案here
Obj-c动作的捆绑由Localizable.strings
获得。
我因此更换了错误的行
[self bundle]
通过
NSString *comment = NSLocalizedString(@"IMPORTED", nil);
一切正常。
希望这也有助于其他人!