CSV & TSV Translation
The CSV/TSV handler (src/formats/csv_tsv.rs) translates delimited text files cell by cell while preserving the row/column structure and any header rows.
How It Works
- Read — The file is parsed using the
csvcrate. For TSV files the delimiter is changed to\t. - Translate — Each non-empty cell value is sent to
TranslationService::translate_text. Empty cells are passed through unchanged. - Write — Translated cell values are written to the output file using the same delimiter and quoting rules as the input.
Because cell values are translated independently, the TranslationService cache is particularly effective here: repeated values (e.g. category names appearing in every row) are translated once and served from cache on subsequent rows.
Error Handling
Parsing errors from the csv crate are automatically converted to AppError::Csv via the From implementation in src/error.rs.
Limitations
- The handler does not attempt to detect or skip header rows automatically. All cells, including headers, are sent for translation. If you want to preserve English headers, pre-process the file before passing it to TMT.
- Cells exceeding
MAX_REQUEST_TEXT_BYTES(5,000 characters) are chunked byTranslationServiceat sentence boundaries before being sent.