Review main Abandoned

88661[BUGFIX] Catch exceptions in LocalizationUtility::translate

Garvin Hicking CR -1 V +1 Easy +37 −3 updated 09/18/25, 18:00

Commit message

In case of malformed language translations, two exceptions can
be thrown by PHP's `sprintf()`: `ArgumentCountError` and `ValueError`.

These can lead to a broken TYPO3 backend, especially in case of
translations files from the localization servers.

With this patch, the possible exceptions are caught to return
a translation string with the error message, so that errors can
still be seen in the output, but should not break the backend.

Actually, the old code already tried to catch this, and was
expecting a FALSE return for `sprintf()` in PHP versions
prior to 8.0. This was converted to exceptions that have
not been caught. Due due missing test coverage, this was
not yet addressed.

Tests are enhanced to cover these error scenarios now.

Review

  • Code review CR -1
    • Benjamin Franzke -1
    • Markus Klein +1
    • Benni Mack -1
  • Verified V +1
    • Markus Klein +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 1112

  1. Garvin Hicking uploaded patch set 1 03/20/25, 19:18

  2. core-ci voted on patch set 1 V +1 03/20/25, 19:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/75907

  3. Benni Mack voted on patch set 1 CR +1 03/20/25, 19:36

  4. Markus Klein voted on patch set 1 CR +1 V +1 03/21/25, 07:00

  5. Benjamin Franzke commented on patch set 1 CR -1 03/21/25, 07:46

    Hm, I don't think that a rendered label `Error: could not translate key "…"` will help editors at all. Imagin seeing that in a button (it overflows the layout and requires a bug report as well) I think we should default to english (that's at least more helpful) and log an error instead. Otherwise this is basically a silent error that only editors will notice, but not developers/integrators.
  6. Benni Mack commented on patch set 1 CR -1 03/21/25, 08:26

    Reply

    hmm, good idea, I think this is even actually a quite simple solution to build. In general, I'm not a fan of this bugfix, because it actually stems from the problem that somebody else(tm) created a wrong XLF, which is a configuration bug, and people need to know this. I'd rather have a check of the XLF files when downloading them to see if they are corrupt.
  7. Garvin Hicking commented on patch set 1 03/21/25, 09:11

    Reply Unresolved

    I see - I mainly restored pre-PHP8 behaviour here. Fallback to en sounds interesting, but what if arguments may be different or even if there is no english/default fallback because an integrator/dev reaquested a specific language variant and it doesn't exist in english?! I would say wrong labels showing up is better than a broken backend/frontend, but let's try to go the fallback route first, althats better than throwing IMO.
  8. Georg Ringer commented on patch set 1 03/21/25, 09:43

    but this can also happens if some extensions provide local xlf files which are bogus ... so not only files from translation server!
  9. Benni Mack commented on patch set 1 04/12/25, 12:09

    current state is not reviewable - I put this on hold by marking it WIP
  10. Benni Mack marked it work in progress 04/12/25, 12:09

  11. Garvin Hicking commented on patch set 1 04/24/25, 14:55

    Related: 102045 (not editing commit msg)
  12. Garvin Hicking abandoned the change 09/18/25, 18:00

    abandoning, I don't think this can reach a conclusion