From 6fcabe720223f4667af4dd804b52444f10d708ea Mon Sep 17 00:00:00 2001 From: Richard Piazza Date: Wed, 15 Apr 2026 11:16:50 -0500 Subject: [PATCH] Update XML Output formatting --- Package.resolved | 4 +-- Package.swift | 2 +- Sources/TranslationCatalog/Catalog.swift | 1 + .../FilesystemContainer.swift | 1 + .../Internal/Resource.swift | 2 +- .../Internal/StringsXml.swift | 11 ++------ .../SQLiteStatement+Expression.swift | 1 + Tests/LocalizerTests/ExportTests.swift | 28 +++++++++---------- .../ExpressionEncoderTests.swift | 6 ++-- 9 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Package.resolved b/Package.resolved index c2b802b..5a99eeb 100644 --- a/Package.resolved +++ b/Package.resolved @@ -68,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/CoreOffice/XMLCoder.git", "state" : { - "revision" : "b1e944cbd0ef33787b13f639a5418d55b3bed501", - "version" : "0.17.1" + "revision" : "b2b5d72345bab9e1938a483cf862b498aeed3796", + "version" : "0.18.1" } } ], diff --git a/Package.swift b/Package.swift index 3ae6ab0..6713a8a 100644 --- a/Package.swift +++ b/Package.swift @@ -36,7 +36,7 @@ let package = Package( .package(url: "https://github.com/richardpiazza/CoreDataPlus.git", from: "0.5.0"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.7.1"), .package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"), - .package(url: "https://github.com/CoreOffice/XMLCoder.git", from: "0.17.1"), + .package(url: "https://github.com/CoreOffice/XMLCoder.git", from: "0.18.1"), .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.16.0"), ], targets: [ diff --git a/Sources/TranslationCatalog/Catalog.swift b/Sources/TranslationCatalog/Catalog.swift index 135a492..d789b41 100644 --- a/Sources/TranslationCatalog/Catalog.swift +++ b/Sources/TranslationCatalog/Catalog.swift @@ -2,6 +2,7 @@ import Foundation /// Interface providing storage and retrieval of the `Expression`s and associated `Translation`s. public protocol Catalog { + // MARK: - Project /// Retrieve all `Project`s in the catalog. diff --git a/Sources/TranslationCatalogFilesystem/FilesystemContainer.swift b/Sources/TranslationCatalogFilesystem/FilesystemContainer.swift index b747afa..e52dfc2 100644 --- a/Sources/TranslationCatalogFilesystem/FilesystemContainer.swift +++ b/Sources/TranslationCatalogFilesystem/FilesystemContainer.swift @@ -125,6 +125,7 @@ extension FilesystemContainer { } extension FilesystemContainer { + // MARK: - Project public func projects() throws -> [Project] { diff --git a/Sources/TranslationCatalogIO/Internal/Resource.swift b/Sources/TranslationCatalogIO/Internal/Resource.swift index 544aa12..f24efc1 100644 --- a/Sources/TranslationCatalogIO/Internal/Resource.swift +++ b/Sources/TranslationCatalogIO/Internal/Resource.swift @@ -13,7 +13,7 @@ struct Resource: Codable, DynamicNodeDecoding, DynamicNodeEncoding { let value: String let formatted: Bool? - static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding { + static func nodeDecoding(for key: any CodingKey) -> XMLDecoder.NodeDecoding { switch key { case CodingKeys.name, CodingKeys.formatted: .attribute diff --git a/Sources/TranslationCatalogIO/Internal/StringsXml.swift b/Sources/TranslationCatalogIO/Internal/StringsXml.swift index 851a37e..5ca2c61 100644 --- a/Sources/TranslationCatalogIO/Internal/StringsXml.swift +++ b/Sources/TranslationCatalogIO/Internal/StringsXml.swift @@ -9,7 +9,7 @@ struct StringsXml: Codable, DynamicNodeDecoding, DynamicNodeEncoding { let resources: [Resource] - static func nodeDecoding(for key: CodingKey) -> XMLDecoder.NodeDecoding { + static func nodeDecoding(for key: any CodingKey) -> XMLDecoder.NodeDecoding { .element } @@ -28,8 +28,8 @@ struct StringsXml: Codable, DynamicNodeDecoding, DynamicNodeEncoding { func encoded() throws -> Data { let encoder = XMLEncoder() - encoder.outputFormatting = [.sortedKeys] - let encoded = try encoder.encode( + encoder.outputFormatting = [.sortedKeys, .prettyPrinted] + return try encoder.encode( self, withRootKey: "resources", header: XMLHeader( @@ -37,11 +37,6 @@ struct StringsXml: Codable, DynamicNodeDecoding, DynamicNodeEncoding { encoding: "UTF-8" ) ) - var string = String(decoding: encoded, as: UTF8.self) - string = string.replacingOccurrences(of: ">", with: ">\n") - string = string.replacingOccurrences(of: ">\n ", with: ">\n") - return string.data(using: .utf8) ?? encoded } } diff --git a/Sources/TranslationCatalogSQLite/SQLiteStatement+Expression.swift b/Sources/TranslationCatalogSQLite/SQLiteStatement+Expression.swift index b821b7c..23033fb 100644 --- a/Sources/TranslationCatalogSQLite/SQLiteStatement+Expression.swift +++ b/Sources/TranslationCatalogSQLite/SQLiteStatement+Expression.swift @@ -18,6 +18,7 @@ extension SQLiteStatement { // MARK: - Expression (Queries) extension SQLiteStatement { + // MARK: Select Expressions static var selectAllFromExpression: Self { diff --git a/Tests/LocalizerTests/ExportTests.swift b/Tests/LocalizerTests/ExportTests.swift index e75568e..361b0cc 100644 --- a/Tests/LocalizerTests/ExportTests.swift +++ b/Tests/LocalizerTests/ExportTests.swift @@ -84,12 +84,12 @@ struct ExportTests { #expect(output == """ - Lingua - Hello World! - - Android - Apple - Web + Lingua + Hello World! + + Android + Apple + Web """) @@ -107,8 +107,8 @@ struct ExportTests { #expect(output == """ - Hola Mundo! - solo en español + Hola Mundo! + solo en español """) @@ -126,12 +126,12 @@ struct ExportTests { #expect(output == """ - Lingua - Hola Mundo! - solo en español - Android - Apple - Web + Lingua + Hola Mundo! + solo en español + Android + Apple + Web """) diff --git a/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift b/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift index c27421d..bf8f0f9 100644 --- a/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift +++ b/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift @@ -42,9 +42,9 @@ struct ExpressionEncoderTests { #expect(output == """ - Hello World! - Hello %s! - Hello %s, welcome to %s! + Hello World! + Hello %s! + Hello %s, welcome to %s! """) }