I'm trying to add a line break to a string in the new Xcode 15 strings catalog, aka xcstrings. Thinking of nothing, I added the usual \n to the place where I want the line break.
But in my SwiftUI view I get to see the actual escaped \n and the text does not break lines. So the text "lorem ipsum\ndolor" gets presented to the user as "lorem ipsum\ndolor".
How can I create a text with intentional line breaks without using multiple independent strings in the catalog?
Solution 1:
Keep Option when adding a new line with Enter.
Solution 2:
Edit manually the xcstrings (which is a JSON file).
If you open the xcstrings file with a text editor, or right click on it, Open as/Source Code, you'll see this:
{
"sourceLanguage" : "en",
"strings" : {
"key1" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "key1\n2"
}
}
}
},
"key2" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "key2\\n2"
}
}
}
}
},
"version" : "1.0"
}
On key2, I write explicitly in the interface "\n" as you tried, and on key1, I kept Option while typing new line.
Seeing in the source \\n explain why it's rendered once in the UI as visually \n and not a new line, since the backslash before the "n" is backslashed (ie escaped)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With