Skip to content

refactor(php): inject IL10N into services, translate exception messages at throw site#24

Merged
vitormattos merged 15 commits intomainfrom
refactor/l10n-literal-strings-in-services
Mar 20, 2026
Merged

refactor(php): inject IL10N into services, translate exception messages at throw site#24
vitormattos merged 15 commits intomainfrom
refactor/l10n-literal-strings-in-services

Conversation

@vitormattos
Copy link
Member

Problem

t() was being called with $exception->getMessage() in controller catch blocks:

return new DataResponse(['message' => $this->l10n->t($exception->getMessage())], Http::STATUS_BAD_REQUEST);

This is incorrect because translation extraction tools scan source code for t('literal string') patterns — they cannot discover dynamic strings.

Solution

  • Inject IL10N into FieldDefinitionService and FieldValueService
  • Call t('literal string') at the throw site inside the services, so exceptions already carry translated messages
  • Controllers use $exception->getMessage() directly in catch blocks (no t() wrapping)

Dynamic fragments (e.g. option name, JSON error) go into the second parameter array as intended by the l10n API.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…erationTest

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…er catch block

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…er catch block

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…tch blocks

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…test

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…test

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
… throws with literal strings

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…ws with literal strings

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…onApiController

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…inApiController

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…Controller

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos vitormattos merged commit f98de17 into main Mar 20, 2026
23 checks passed
@vitormattos vitormattos deleted the refactor/l10n-literal-strings-in-services branch March 20, 2026 16:51
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.

1 participant