1

I have the following in a swift file which is loaded on first app use:

        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")]

I then try to create the German localization in localizable.strings (German):

/* 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.
"""

But I get the following error on compile:

"read failed: Couldn't parse property list because the input data was in an invalid format"

Is it even possible to use multi-line strings in localizable files?

I would like to take advantage of the paragraph formatting ability of multi-line strings, when I localize my strings.

Tirna
  • 383
  • 1
  • 12
  • Possibly helpful: https://stackoverflow.com/q/51478373/1187415. – Martin R Jul 03 '21 at 20:16
  • As Martin hints at the end of his answer, you should use short codes for keys, not actual text. In the Strings file, do something like `"welcomescreen.label1" = "your text";` then `"welcomescreen.label2" = "some other text";`, etc, for all languages including the base language, and use this coded key with NSLocalizedString instead of real text. – Eric Aya Jul 03 '21 at 22:43

1 Answers1

0

It looks like you might have missed out the ; at the end of the string declaration and you only need to use 1 " when defining multiline strings in the localisable file, so try changing it to:

/* 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.
";
Ayrton CB
  • 454
  • 2
  • 9
  • Hm, okay, just updated my answer, I believe you don't need to use the three """ you can just use 1 – Ayrton CB Jul 03 '21 at 20:11
  • It works with your suggestion, but only if I use single quotes in the welcome screen source file as well. Which means the text looses it's paragraph formatting! – Tirna Jul 03 '21 at 20:37