objective-c本地化字符串文件中的多行字符串 [英] Multi-line strings in objective-c localized strings file

查看:133
本文介绍了objective-c本地化字符串文件中的多行字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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中,我可以像这样创建一个人类可读的多行字符串:

I'd rather not make each line its own string with a unique key. In Objective-C, I can create a human-readable multiline string like so:

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

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

I tried to put that in a .strings file with:

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

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

But I get the following error at build time:

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

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

I can concatenate it all together like this:

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

但维持这一点很麻烦,特别是当电子邮件变得更长时。

But that will be a mess to maintain, particularly as the email gets longer.

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

Is there a way to do this in a localized strings file? I've already tried adding backslashes at the end of each line, to no avail.

推荐答案

直接使用新行。

"email" = "Hello %@,

Check out %@.

Sincerely,

%@";

这篇关于objective-c本地化字符串文件中的多行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆