Localizable.strings 中的多行字符串

问题描述

我在第一次使用应用程序时加载的 swift 文件中有以下内容

        let descriptions = [NSLocalizedString("""
                                                 Hyperpolyglot will help you learn words and phrases in
                                                 up to 10 languages. Add languages,words and phrases
                                                 with the aid of phrase books. Learn a word in many
                                                 languages while learning it in one.

                                                 Use your native keyboard and transliteration,if you just
                                                 want to speak a language. Take it up a level! Switch
                                                 keyboard languages,and also learn to read and write.
                                              """,comment: "Welcome screen 1"),NSLocalizedString("""
                                                 Associate a word with an image or drawing. Grab images
                                                 from your favourite search engine,or make your own line
                                                 drawings.

                                                 Do you really kNow the word? Answer foreign words
                                                 which have missing letters.

                                                 Tap the lightbulb if you need hints.
                                              """,comment: "Welcome screen 2"),NSLocalizedString("""
                                                 Buy the full copy to add unlimited words and unlock the
                                                 drawing canvas!
                                              """,comment: "Welcome screen 3")]

然后我尝试在 localizable.strings(德语)中创建德语本地化:

/* Welcome screen 1 */
"""
   Hyperpolyglot will help you learn words and phrases in
   up to 10 languages. Add languages,words and phrases
   with the aid of phrase books. Learn a word in many
   languages while learning it in one.

   Use your native keyboard and transliteration,if you just
   want to speak a language. Take it up a level! Switch
   keyboard languages,and also learn to read and write.
""" = """
   Hyperpolyglot hilft Ihnen,Wörter und Sätze in bis zu
   10 Sprachen zu lernen. Fügen Sie Sprachen,Wörter und
   Sätze mit Hilfe von Sprachführern hinzu. Lernen Sie ein
   Wort in vielen Sprachen,während Sie es in einer lernen.

   Verwenden Sie Ihre native Tastatur und Transliteration,wenn Sie nur eine Sprache sprechen möchten. Bring es auf
   ein Level! Wechseln Sie die Tastatursprachen und lernen
   Sie auch,zu lesen und zu schreiben.
"""

但是我在编译时遇到以下错误

“读取失败:无法解析属性列表,因为输入数据的格式无效”

甚至可以在可本地化的文件中使用多行字符串吗?

我想在本地化字符串时利用多行字符串的段落格式化功能

解决方法

看起来您可能遗漏了字符串声明末尾的 ; 并且在可本地化文件中定义多行字符串时只需要使用 1 ",因此尝试将其更改为:

/* Welcome screen 1 */
"
Hyperpolyglot will help you learn words and phrases in
up to 10 languages. Add languages,words and phrases
with the aid of phrase books. Learn a word in many
languages while learning it in one.

Use your native keyboard and transliteration,if you just
want to speak a language. Take it up a level! Switch
keyboard languages,and also learn to read and write.
" = "
Hyperpolyglot hilft Ihnen,Wörter und Sätze in bis zu
10 Sprachen zu lernen. Fügen Sie Sprachen,Wörter und
Sätze mit Hilfe von Sprachführern hinzu. Lernen Sie ein
Wort in vielen Sprachen,während Sie es in einer lernen.

Verwenden Sie Ihre native Tastatur und Transliteration,wenn Sie nur eine Sprache sprechen möchten. Bring es auf
ein Level! Wechseln Sie die Tastatursprachen und lernen
Sie auch,zu lesen und zu schreiben.
";

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...