Objective-C本地化字符串文件中的多行字符串
收藏

I have a template for an email that I've put in a localized strings file, and I'm loading the string with the NSLocalizedString macro.

我不想用唯一的键使每一行成为自己的字符串。在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%@";

但这将造成混乱,尤其是随着电子邮件的发送时间延长。

有没有办法在本地化的字符串文件中执行此操作?我已经尝试过在每行末尾添加反斜杠,但无济于事。

最佳答案

只需直接使用新行即可。

"email" = "Hello %@,

Check out %@.

Sincerely,

%@";

    公众号
    关注公众号订阅更多技术干货!