32

我有一个已放入本地化字符串文件的电子邮件模板,并且正在使用NSLocalizedString宏加载字符串。

我宁愿不要用唯一的键使每一行都成为自己的字符串。在 Objective-C 中,我可以创建一个人类可读的多行字符串,如下所示:

NSString *email = @"Hello %@,\n"
    "\n"
    "Check out %@.\n"
    "\n"
    "Sincerely,\n"
    "\n"
    "%@";

我试图把它放在一个 .strings 文件中:

"email" = "Hello %@,\n"
    "\n"
    "Check out %@.\n"
    "\n"
    "Sincerely,\n"
    "\n"
    "%@";

但我在构建时收到以下错误:

CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
email-template.strings: Unexpected character " at line 1
Command /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copystrings failed with exit code 1

我可以像这样将它们连接在一起:

"email" = "Hello %@,\n\nCheck out %@.\n\nSincerely,\n\n%@";

但这将是一团糟,尤其是当电子邮件变得更长时。

有没有办法在本地化的字符串文件中做到这一点?我已经尝试在每行末尾添加反斜杠,但无济于事。

4

1 回答 1

65

只需直接使用新行。

"email" = "Hello %@,

Check out %@.

Sincerely,

%@";
于 2010-06-03T18:20:45.333 回答