Skip to content

Extract translations from shared templates under layout domain (#2162) - #4202

Open
mitapujari-05 wants to merge 1 commit into
elementary:masterfrom
mitapujari-05:fix/issue-2162-translation-extraction
Open

mitapujari-05 wants to merge 1 commit into
elementary:masterfrom
mitapujari-05:fix/issue-2162-translation-extraction

Conversation

@mitapujari-05

Copy link
Copy Markdown

Summary

Fixes #2162.

Updates Extract.php and Translation.php to extract translations from shared templates in _templates/ (header.php, alert.php, footer.php, legacy.php) and combine them under the single layout domain, rather than failing or creating separate template-specific translation files.

Changes

  • _backend/Console/Extract.php:
    • Added translateLayout() to extract shared templates in a unified layout environment under the layout domain.
    • Added support for --page layout and mapped individual template inputs (e.g. --page _templates/header) to layout.
    • Configured user agent during extraction so legacy browser warning strings in legacy.php are included.
    • Output JSON with JSON_UNESCAPED_SLASHES to match standard formatting.
  • _backend/Console/Translation.php:
    • Mapped all _templates/ paths from L10n::pages() into the single layout domain and deduplicated them.
    • Handled CLI --page argument so --page layout or --page _templates/... target the layout domain.
    • Normalized keys when preserving existing translations to ensure formatting whitespace differences do not drop existing localized strings.
    • Enforced LF (\n) line endings matching .editorconfig.

Testing

  • Verified Extract.php --page layout extracts all strings from header.php, alert.php, footer.php, and legacy.php.
  • Verified Translation.php -p layout updates translations under layout.json while preserving existing translations.
  • Verified isolation of regular pages (e.g., index.php).
  • Verified PSR-2 compliance with phpcs.
  • Ran php _tests/translations.php (all 584 translation files passed, 0 errors).

@lewisgoddard
lewisgoddard self-requested a review October 20, 2026 11:15
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.

Translation extract scripts do not extract from template files

1 participant