objective-c本地化字符串文件中的多行字符串

时间:2010-06-03 18:18:33

标签: objective-c iphone localization nslocalizedstring

我有一个电子邮件模板,我已将其放入本地化的字符串文件中,并且我正在使用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%@";

但这将是一个混乱的维护,特别是当电子邮件变得更长时。

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

1 个答案:

答案 0 :(得分:50)

直接使用新行。

"email" = "Hello %@,

Check out %@.

Sincerely,

%@";