Skip to content

Type the module translator example against the interface - #2166

Draft
boo-code wants to merge 1 commit into
PrestaShop:9.xfrom
boo-code:fix/module-translator-type-hint-34138
Draft

Type the module translator example against the interface#2166
boo-code wants to merge 1 commit into
PrestaShop:9.xfrom
boo-code:fix/module-translator-type-hint-34138

Conversation

@boo-code

@boo-code boo-code commented Sep 6, 2026

Copy link
Copy Markdown

The "Other classes" example in modules/creation/module-translation/new-system.md is what
PrestaShop/PrestaShop#34138 reports. It is broken three ways:

  • public function __construct(Translator $translator) names a concrete class. The container decides
    which translator a module receives and the debug environment decorates it, so a class following the
    example works with debug off and throws with it on.
  • Translator is unqualified, so inside a module namespace it resolves to a class that does not exist.
  • $this->translator = $translator is missing its semicolon, so the snippet does not compile.

The change types the parameter as PrestaShopBundle\Translation\TranslatorInterface, adds the use
line the snippet needs, fixes the semicolon, and says in one sentence why the interface rather than a
concrete class.

Paired with a core branch (fix/translator-contract-is-the-interface-34138, base develop) that makes
that interface declare everything the core calls on a translator, since it previously did not declare
setLocale() or getCatalogue().

The container decides which translator a module receives and the debug
environment decorates it, so the example's Translator type hint made a
class that follows the documentation work with debug off and fail with it
on. The unqualified name also resolved to nothing in a module namespace,
and the assignment was missing its semicolon.
@github-actions github-actions Bot added the 9.x label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant