CsvFormat.h header
#include <ew/app/CsvFormat.h>
Namespace ew::app
Functions
ew::core::foundation::Result< std::vector< ImportedTranslation > > ew::app::localization::readTranslationCsv(const QString &text)
Parses text as a translation CSV.
Columns are located BY HEADER NAME, never by position. A translator working in a spreadsheet reorders columns, hides them, and adds their own; a positional reader would silently import the wrong field as the translation, which is worse than failing. Unrecognized columns are ignored.
A leading U+FEFF is stripped. Excel writes a UTF-8 BOM, and it would otherwise become part of the first header's name – so the file would parse as having no id column at all and import nothing, for a reason invisible to the person looking at it.
A row whose id does not parse is skipped rather than failing the file, as in the XLIFF reader: one mangled row should cost that row. A file with no id and target columns is an error – that is not a translation CSV, and silently importing zero rows from it would look like success.
QString ew::app::localization::writeTranslationCsv(const std::vector< TranslationWorkItem > &work)
Serializes work as CSV – the format for a translator who has a spreadsheet rather than a CAT tool, which for a novelist's friend-who-speaks-Spanish is the normal case.
Columns are id, context, source, target, status. context and status are there for the human: neither is read back as authority. The file is written with a header row, and the reader uses it (see readTranslationCsv).
Quoting is ew::app::text::escapeDelimitedField, shared with the spreadsheet's CSV – prose is full of commas, quotes and newlines, and one set of quoting rules is the only way both features stay correct together.