Skip to content

[Improvement] Migrate admin translation CSV export to League/CSV - #1968

Open
xIrusux wants to merge 2 commits into
2026.xfrom
feature/1842-translation-csv-league-csv
Open

[Improvement] Migrate admin translation CSV export to League/CSV#1968
xIrusux wants to merge 2 commits into
2026.xfrom
feature/1842-translation-csv-league-csv

Conversation

@xIrusux

@xIrusux xIrusux commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Migrates the admin Translation CSV export (Translation\Service\CsvService) from hand-rolled string concatenation to League\Csv\Writer.

Resolves #1842 (PEES-945).

Why

removeLineBreaks() flattened all newlines/tabs inside a cell to single spaces, destroying multi-line translation values on export. Escaping was also non-standard (embedded " became the HTML entity " instead of RFC 4180 quote-doubling, and every field was force-wrapped in quotes).

league/csv (^9.27) is already a dependency and already used for the grid export in Export\Service\CsvExportService — this reuses the same Writer::fromString()setDelimiter()insertOne()/toString() pattern.

Changes

  • Remove buildCsvContent() (rebuilt on Writer), buildHeaderRow(), buildDataRows(), formatCellValue(), removeLineBreaks().
  • Line breaks inside cells are now preserved via proper RFC 4180 quoting.
  • Untouched: export() orchestration, escapeCsvRecord() CSV-injection guard, the UTF-8 BOM + response headers in generateCsvResponse(), and all import-dialect (determineCsvDialect()) code.
  • Adds tests/Unit/Translation/Service/CsvServiceTest.php.

Acceptance criteria

  • Migration to League/CSV evaluated and decided
  • removeLineBreaks() string-replacement logic migrated to League/CSV
  • CSV export still works generally
  • CSV export with line-break values works with migrated code

Behavior change

Exported files now use minimal (standards-compliant) quoting and retain embedded line breaks instead of collapsing them to spaces. Verified against Excel and the Studio CSV import.

Tests

vendor/bin/codecept run Unit tests/Unit/Translation/Service/CsvServiceTest.php → 6 passing (line-break preservation, quote-doubling, delimiter enclosure, empty column, non-string cast).

🤖 Generated with Claude Code

Replace the hand-rolled string concatenation in Translation CsvService with
League\Csv\Writer (already a dependency, already used by CsvExportService).

Previously removeLineBreaks() flattened newlines/tabs inside a cell to single
spaces, destroying multi-line translation values, and quotes were escaped as
" rather than RFC 4180 quote-doubling. Line breaks are now preserved via
proper CSV quoting.

Adds unit tests covering line-break preservation, quote-doubling, delimiter
enclosure, empty columns and non-string cast.

Fixes #1842

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 28, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Verdict: Needs changes. The PR correctly moves translation CSV generation to League CSV, preserving multiline values, but leaves RFC 4180 escaping incomplete.

Changes:

  • Replaces manual CSV construction with League\Csv\Writer.
  • Preserves line breaks and standardizes record generation.
  • Adds focused CSV serialization tests.

Assessment:

  • Root cause: Addressed at the owning service boundary (CsvService.php:130-162).
  • Call sites: The sole production caller uses the new implementation (CsvService.php:66).
  • Compatibility: No public signature changes; export quoting intentionally changes.
  • Tests: Cover primary behavior, but omit backslash-before-quote escaping (CsvServiceTest.php:70-78).
  • Remaining issues: Explicitly disable League CSV’s proprietary escape character (CsvService.php:133-135) and chain converted exceptions (CsvService.php:143-144).
  • Docs: No dedicated export documentation or changelog was found.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Translation/Service/CsvService.php Migrates translation export serialization to League CSV.
tests/Unit/Translation/Service/CsvServiceTest.php Tests CSV formatting and multiline preservation.

Comment thread src/Translation/Service/CsvService.php
Comment thread src/Translation/Service/CsvService.php Outdated
@xIrusux xIrusux added this to the 2026.3.0 milestone Jul 29, 2026
@xIrusux xIrusux self-assigned this Jul 29, 2026
…rt exceptions

Addresses the review feedback on #1968:

- Writer kept PHP's default escape character `\`, so a backslash directly
  before a quote suppressed RFC 4180 quote doubling and produced output that
  standards-compliant readers mis-parse. setEscape('') makes the export
  fully RFC 4180 compliant.
- Chain the caught League CSV exception into EnvironmentException so the
  original type and stack trace survive, matching the existing convention
  elsewhere in the bundle.

Adds two serialization tests covering a backslash before a quote and a value
ending in a backslash.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@xIrusux
xIrusux requested review from heigpa and lukmzig and removed request for heigpa July 29, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Migrate Admin Translation CSV Export to use League CSV

3 participants