Skip to content

Add comprehensive locale testing and improve translation coverage - #28

Merged
codeling merged 6 commits into
mainfrom
claude/locale-tests
Oct 3, 2026
Merged

codeling merged 6 commits into
mainfrom
claude/locale-tests

Conversation

@codeling

@codeling codeling commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Summary

This change adds comprehensive test coverage for locale files and improves translation coverage throughout the codebase by extracting hardcoded English strings into translatable keys.

Key Changes

New Tests

  • tests/Unit/LocaleFilesTest.php: Validates all locale files for correctness

    • Ensures locale files define valid string arrays with no duplicates
    • Verifies UTF-8 encoding and absence of control characters
    • Validates date format strings
    • Checks that placeholder counts match between keys and translations
    • Reports missing translations without failing (allows incomplete translations)
    • Detects unused translation keys in locale files
  • tests/Integration/LocaleTest.php: Tests locale functionality in the running application

    • Verifies all main views render successfully with each locale
    • Checks HTML language attribute and charset are set correctly
    • Validates toolbar tooltips, titles, and dates use translations
    • Tests form buttons, list headers, and upload script messages are translated
    • Verifies error messages, upload confirmations, and markdown help examples are translated
  • tests/Integration/LocaleEscapingTest.php: Security test for translation escaping

    • Ensures translations with markup and quotes are properly escaped
    • Verifies malicious payloads in translations cannot break out of attributes or inject scripts

Code Improvements

  • index.php: Extracted hardcoded strings into translatable keys

    • Markdown syntax examples in the formatting help drawer
    • Error messages for page creation, saving, and git operations
    • Login disabled warning message
    • Similar page suggestion note
    • Upload script messages (JavaScript)
  • functions.php: Added __js() function for translating JavaScript string literals

    • Properly escapes translations for use in inline JavaScript
    • Uses JSON encoding with appropriate HTML entity flags
  • auth.php: Made IP restriction message translatable (with fallback for api.php)

Locale File Updates

  • locales/en.php: Restructured to only contain entries that differ from their keys

    • Added documentation explaining the English locale approach
    • Removed redundant entries where key equals value
  • locales/de.php, locales/oc.php, locales/ja.php:

    • Removed unused 'Recent' and 'Exit' entries
    • Changed 'Log Out' to 'Log out' for consistency
    • Added new translations for extracted strings
    • Fixed character restriction message (changed '/' to '..')

Notable Implementation Details

  • The __() function returns the key itself if no translation exists, so the English locale only needs entries where the translation differs from the key
  • The __js() function uses html_entity_decode() to convert HTML entities back to characters before JSON encoding, ensuring proper JavaScript string literals
  • Tests use data providers to run the same test suite against all available locales
  • Missing translations are reported as incomplete tests rather than failures, allowing gradual translation coverage

https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY

claude added 6 commits October 3, 2026 20:38
…nd oc.php

Unit tests check the locale files (valid, no duplicate keys, UTF-8, date formats,
all texts of the code in en.php); integration tests run the views with every
locale and with a generated locale containing markup.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY
__() returns the key for texts without an entry, so en.php only needs the
entries that differ from their key. The locale tests compare the other
languages with the texts used in the code instead. Removes the unused keys
Recent and Exit (Exit renamed to Log out in ja.php).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY
…it message label, upload alerts, page errors

Adds __js() for texts in inline scripts, German translations, and tests that
check these texts for every locale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY
…uests, IP and git errors

Adds German translations and per-locale tests for these texts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY
Also fixes the underscore emphasis example, which was closed with an asterisk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnF3JNHe2m9RQM1BRKdBMY
@codeling
codeling merged commit 9650d4f into main Oct 3, 2026
15 checks passed
@codeling
codeling deleted the claude/locale-tests branch October 5, 2026 15:03
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.

2 participants