[Improvement] Migrate admin translation CSV export to League/CSV - #1968
Open
xIrusux wants to merge 2 commits into
Open
[Improvement] Migrate admin translation CSV export to League/CSV#1968xIrusux wants to merge 2 commits into
xIrusux wants to merge 2 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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. |
…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>
|
lukmzig
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Migrates the admin Translation CSV export (
Translation\Service\CsvService) from hand-rolled string concatenation toLeague\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 inExport\Service\CsvExportService— this reuses the sameWriter::fromString()→setDelimiter()→insertOne()/toString()pattern.Changes
buildCsvContent()(rebuilt onWriter),buildHeaderRow(),buildDataRows(),formatCellValue(),removeLineBreaks().export()orchestration,escapeCsvRecord()CSV-injection guard, the UTF-8 BOM + response headers ingenerateCsvResponse(), and all import-dialect (determineCsvDialect()) code.tests/Unit/Translation/Service/CsvServiceTest.php.Acceptance criteria
removeLineBreaks()string-replacement logic migrated to League/CSVBehavior 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