XliffFormat.h header

#include <ew/app/XliffFormat.h>

Namespace ew::app

XliffFile struct

struct ew::app::XliffFile

The contents of an XLIFF file.

Members

QString ew::app::localization::XliffFile::sourceLanguage

BCP-47 tag of the language translated FROM.

QString ew::app::localization::XliffFile::targetLanguage

BCP-47 tag of the language translated INTO.

QString ew::app::localization::XliffFile::original

What the file is a translation of – the project's name, carried through untouched.

std::vector<ImportedTranslation> ew::app::localization::XliffFile::units

The units, in file order.

Functions

ew::core::foundation::Result< XliffFile > ew::app::localization::readXliff(QStringView xml)

Parses xml as XLIFF 1.2.

What comes back is treated as a claim, not as truth. A returning file's own idea of whether a unit is current cannot be trusted – it was written before the translator started, and the writer may have revised the prose in the meantime – so only the target text and the review flag are taken from it. Whether a translation is stale is recomputed against the project by ew::core::localization::TranslationCatalog::statusFor.

A unit whose id does not parse as an address is skipped rather than failing the file: one mangled row in a thousand-unit file returned from an external tool should cost that row, not the translator's whole afternoon. A file that is not XLIFF at all is an error.

QString ew::app::localization::writeXliff(const std::vector< TranslationWorkItem > &work, const QString &sourceLanguage, const QString &targetLanguage, const QString &original)

Serializes work as XLIFF 1.2, the interchange format every translation tool reads.

1.2 rather than 2.x on purpose: it is what the tools a working translator actually has (memoQ, Trados, OmegaT, Poedit) support without qualification, and this feature is worthless if the file will not open.

original names what is being translated (the project's name). sourceLanguage must be supplied by the caller: a project has no language setting of its own – the K1 survey confirmed there is no locale concept anywhere in libs/core or libs/app – and inventing one here would be a project-format change this item was not asked for.

The status becomes the target's state, and one mapping is not the obvious one. Stale means the target translates text that no longer exists, so it is written needs-translation and NOT needs-review-translation: a review says "this is right, please check it", which would send a translator to skim something that has to be rewritten. A New unit is written with no target element at all, which is what a tool expects of untranslated content.

SourceFormat becomes the unit's datatype, so a translator is told which of their strings is markup. Markdown and Fountain are not XLIFF-defined values, so they take the specification's x- prefix for custom types – x-markdown, x-fountain.