Skip to content

[Translation] Message domains with dot not working #31400

Closed
@mfrieling

Description

@mfrieling

Symfony version(s) affected: 4.2.x

Description
Translation message domains containing a dot (.) are not loaded, neither with nor without caching.

How to reproduce
Create a translation in any controller or twig template using a message domain like app.security:

// ...

class SecurityController extends AbstractController {
  /**
   * @Route("/login", name="app_login")
   */
  public function login(AuthenticationUtils $authenticationUtils, TranslatorInterface $translator): Response {
    // ...
    $test = $translator->trans('login.page.title', [], 'app.security', 'en');
    // ...
  }
}

Extracting translations with php bin/console translation:update --dump-messages --force en will correctly create the file translations/app.security.en.xlf with the login.page.title translation. But even a rm -rf var/cache && php bin/console clear:cache will never load this translation file.

After spending hours with searching in the Symfony docs, Google and Stack Overflow I was sure that translation is configured correctly and must work. So I removed the message domain and the translations/messages.en.xlf got loaded. Then I tried another message domain security and the seucrity.en.xlf got loaded as well. This lead me to the conclusion that there must be a bug with message domains containing a dot only, as further tests with dashed worked fine.

Possible Solution
I could not locate where the bug happens because that might be in generated code and I don't know where this code is generated (some compiler passes possibly). So please, either fix this bug or if there is a reason why message domains must not contain dots document this clearly everywhere where message domains are mentioned (or link to Translation Component - Using Message Domains where it will be documented) including the why, because in my opinion the concept of Keyword Messages should not only be able to apply to message keys but message domains as well.

And if ti will not be supported, of course change the message extractor to report an error when it finds a message domain containing a dot instead of correctly generating the translation files.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions