BLACK FRIDAY: Save 50% on all books and bundles! >>

SOLVED: Unable to localise multiline strings

Forums > Swift

See title. Localisations for regular strings work, but multiline strings stay as is. Any ideas what could cause this?

   

What does not work? The String isn't translated or something else?

   

It's not translated at all, it just stays in English. I can use \n instead, but it looks awful in the editor.

It would be great if someone could confirm this. It seems too obvious of a bug to miss.

   

Has your language key line breaks or only the translated string? If so, I would remove it from the key and only translate the string. Usually, because of laziness, in the English version of my language file the key and the translation is the same. But in this case I would use a key without line breaks.

   

The multi line string has line breaks yes. But what difference should it make? It should parse the whole thing as one string.

   

I think you misunderstood my question. For example, I have the following in my Localizable.strings files:

//English
"baseTwo" = "
1st Vaccination:\t\t2. Month
2nd Vaccination:\t4. Month
3rd Vaccination:\t11. - 14. Month
";

//German
"baseTwo" = "1. Impfung:\t\t2. Monat
2. Impfung:\t4. Monat
3. Impfung:\t11. - 14. Monat
";

This works exactly as it should. Usually, the English key and English translations in my file are the same. But in this case I decided to shorten the key to baseTwo because the key has to match exactly, otherwise it doesn't work. With multiline strings as key this is too error prone. That's why I asked. Where I can't get it to work is in SwiftUI preview canvas. But in the app itself it's fine. In the Localizable.strings you don't use the syntax of Swift mulitline strings.

1      

Ah, I see. Thank you for your explanation, I misunderstood indeed.

   

Save 50% in my Black Friday sale.

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.