UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

3      

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

3      

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.

3      

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.

3      

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

3      

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.

4      

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

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.