Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/TranslationCatalogIO/Internal/StringsXml.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ struct StringsXml: Codable, DynamicNodeDecoding, DynamicNodeEncoding {
func encoded() throws -> Data {
let encoder = XMLEncoder()
encoder.outputFormatting = [.sortedKeys, .prettyPrinted]
return try encoder.encode(
let encoded = try encoder.encode(
self,
withRootKey: "resources",
header: XMLHeader(
version: 1.0,
encoding: "UTF-8"
)
)
var string = String(decoding: encoded, as: UTF8.self)
string = string.replacingOccurrences(of: "'", with: "\\'")
string = string.replacingOccurrences(of: " ", with: " ") // Non-Breaking Space
return string.data(using: .utf8) ?? encoded
}
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/TranslationCatalogTests/ExpressionEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ExpressionEncoderTests {
Expression(
id: UUID(uuidString: "5870E853-35B9-4C71-B8D6-7EA922C72835")!,
key: "EXP_03",
value: "Hello %s, welcome to %s!",
value: "Hello %s, welcome to '%s'!", // 'Hello{Non-Breaking-Space}%s
languageCode: .english
),
]
Expand All @@ -44,7 +44,7 @@ struct ExpressionEncoderTests {
<resources>
<string name="EXP_01">Hello World!</string>
<string name="EXP_02">Hello %s!</string>
<string formatted="false" name="EXP_03">Hello %s, welcome to %s!</string>
<string formatted="false" name="EXP_03">Hello&#160;%s, welcome to \\'%s\\'!</string>
</resources>
""")
}
Expand All @@ -60,7 +60,7 @@ struct ExpressionEncoderTests {
#expect(output == """
"EXP_01" = "Hello World!";
"EXP_02" = "Hello %@!";
"EXP_03" = "Hello %@, welcome to %@!";
"EXP_03" = "Hello\\U00A0%@, welcome to '%@'!";
""")
}

Expand All @@ -76,7 +76,7 @@ struct ExpressionEncoderTests {
{
"EXP_01" : "Hello World!",
"EXP_02" : "Hello %s!",
"EXP_03" : "Hello %s, welcome to %s!"
"EXP_03" : "Hello %s, welcome to '%s'!"
}
""")
}
Expand Down
Loading