Non-breaking space Xcode 15 XCStrings

I have a problem with non-breaking space in new xcstrings. For example, I have a such code

    let text = "Hello\u{00a0}world!"
    let label = UILabel()
    label.text = text

And this code outputs nice string "Hello world!" with non-breaking space.

But if I try to put this string in Localizable.xcstring by key test_key, and then use this string, it won't work

    let text = String(localized: "test_key")
    let label = UILabel()
    label.text = text

This code will show me Hello\u{00a0}world!. This is because swift adding additional \ symbol before \u{00a0} under hood. And of course \\u{00a0} will be displayed as \u{00a0}.

Is there a way to use non-breaking space in new .xcstrings?

Replies

Just embed the desired character directly in your localized string, the same as any emoji or other non-ASCII character.

Consider: if the xcstrings format required using source code style escape sequences for non-ASCII characters, it wouldn’t be very friendly to anyone making localizations for most non-English languages in the world. So it just accepts all characters directly. Note the underlying format is JSON encoded in UTF-8, so it can store all possible characters.