XCSWriter handles the persistence side of the package. It can serialize a typed Catalog, apply targeted StringPatch updates to existing JSON bytes, and write the result to disk.
invalidJSONinvalidCatalogShape(path:)writeFailed(path:)
public static func serialize(
_ catalog: Catalog,
prettyPrinted: Bool = true,
sortedKeys: Bool = true
) throws -> Datapublic static func apply(
patches: [StringPatch],
to originalData: Data,
prettyPrinted: Bool = true,
sortedKeys: Bool = true
) throws -> Datapublic static func write(_ data: Data, to fileURL: URL) throws
public static func write(
_ catalog: Catalog,
to fileURL: URL,
prettyPrinted: Bool = true,
sortedKeys: Bool = true
) throwsSerialize a typed catalog:
import XCSWriter
let data = try XCSWriter.serialize(catalog)
try XCSWriter.write(data, to: outputURL)Apply patches returned by the translator:
let updatedData = try XCSWriter.apply(patches: result.patches, to: originalData)
try XCSWriter.write(updatedData, to: outputURL)Write a typed catalog directly:
try XCSWriter.write(catalog, to: outputURL)prettyPrintedandsortedKeysdefault totruefor stable, readable output.- Patch application preserves existing sibling fields and only updates the targeted path.
- Missing entry, localization, and variation containers are synthesized automatically during patch application.
applyexpects the original data to be valid JSON with a catalog-like root object containingstrings.
If you are starting from a parsed catalog and want to persist translation updates, the common pairing is XCSTranslator plus XCSWriter.apply.