mattcomi/xliffkit
A Swift framework for parsing and modifying [XLIFF](https://en.wikipedia.org/wiki/XLIFF) files.
Usage
Import the framework:
import XLIFFKitOpening an XLIFF:
let document = try XLIFFDocument(data: data)Iterating through the XLIFF's translation units:
for file in document.files {
for translationUnit in file.body.translationUnits {
print(translationUnit.source, translationUnit.target)
}
}Where a XLIFFTranslationUnit is:
public struct XLIFFTranslationUnit: Hashable {
public let uuid: UUID
public let id: String
public let source: String
public let note: String?
public var target: String?
public var state: XLIFFState?
}Modifying a translation unit:
let file = document.files[0]
var translationUnit = file.body.translationUnits[0]
translationUnit.target = "New value"
translationUnit.state = .needsReviewTranslation
document.updateTranslationUnit(forFileUUID: file.uuid, to: translationUnit)The UUID is not present in the XLIFF; one is generated for files and translation units. It is used to refer to and track elements in the document.
After making a modification, document.hasUnsavedChanges will become true. Call document.commitUnsavedChanged() to write the changes back to the underlying XML document.
Saving changes:
if document.hasUnsavedChanges {
document.commitUnsavedChanges()
}
let newData = document.xmlData()Package Metadata
Repository: mattcomi/xliffkit
Default branch: main
README: README.md