sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
339 stars 488 forks source link

sonata_user_already_authenticated no longer translated #1265

Closed mazsudo closed 3 years ago

mazsudo commented 3 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.76.0          3.78.0             The missing Symfony Admin Generator
sonata-project/block-bundle              3.21.0          4.4.0              Symfony SonataBlockBundle
sonata-project/cache                     1.1.1           2.0.1              Cache library
sonata-project/cache-bundle              2.4.2           3.2.1              This bundle provides caching services
sonata-project/classification-bundle     3.13.2          3.13.2             Symfony SonataClassificationBundle
sonata-project/datagrid-bundle           2.5.0           3.2.0              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.9.1           1.10.1             Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.23.0          3.24.0             Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.11.1          2.4.1              Lightweight Exporter library
sonata-project/form-extensions           1.6.0           1.6.0              Symfony form extensions
sonata-project/formatter-bundle          4.x-dev 679dc39 dev-master 3395a61 Symfony SonataFormatterBundle
sonata-project/google-authenticator      2.2.0           2.2.0              Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle               2.9.0           2.9.0              Symfony SonataIntlBundle
sonata-project/media-bundle              3.27.0          3.27.0             Symfony SonataMediaBundle
sonata-project/notification-bundle       3.9.0           3.10.0             Symfony SonataNotificationBundle
sonata-project/page-bundle               3.19.0          3.19.0             This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.11.0          2.12.0             Symfony SonataSeoBundle
sonata-project/twig-extensions           1.4.1           1.4.1              Sonata twig extensions
sonata-project/user-bundle               4.8.0           4.9.0              Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                      v4.4.14 v5.1.7  Symfony Asset Component
symfony/browser-kit                v5.1.6  v5.1.7  Symfony BrowserKit Component
symfony/cache                      v4.4.14 v5.1.7  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.2.0  Generic abstractions related to caching
symfony/config                     v4.4.14 v5.1.7  Symfony Config Component
symfony/console                    v4.4.14 v5.1.7  Symfony Console Component
symfony/css-selector               v5.1.6  v5.1.7  Symfony CssSelector Component
symfony/debug                      v4.4.14 v4.4.15 Symfony Debug Component
symfony/debug-bundle               v5.1.6  v5.1.7  Symfony DebugBundle
symfony/debug-pack                 v1.0.8  v1.0.9  A debug pack for Symfony projects
symfony/dependency-injection       v4.4.14 v5.1.7  Symfony DependencyInjection Component
symfony/doctrine-bridge            v4.4.14 v5.1.7  Symfony Doctrine Bridge
symfony/dom-crawler                v5.1.6  v5.1.7  Symfony DomCrawler Component
symfony/dotenv                     v4.4.14 v5.1.7  Registers environment variables from a .env file
symfony/error-handler              v4.4.14 v5.1.7  Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.14 v5.1.7  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.9  Generic abstractions related to dispatching event
symfony/expression-language        v5.1.6  v5.1.7  Symfony ExpressionLanguage Component
symfony/filesystem                 v4.4.14 v5.1.7  Symfony Filesystem Component
symfony/finder                     v4.4.14 v5.1.7  Symfony Finder Component
symfony/flex                       v1.9.4  v1.9.10 Composer plugin for Symfony
symfony/form                       v4.4.14 v5.1.7  Symfony Form Component
symfony/framework-bundle           v4.4.14 v5.1.7  Symfony FrameworkBundle
symfony/http-client                v5.1.6  v5.1.7  Symfony HttpClient component
symfony/http-client-contracts      v2.2.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v4.4.14 v5.1.7  Symfony HttpFoundation Component
symfony/http-kernel                v4.4.14 v5.1.7  Symfony HttpKernel Component
symfony/intl                       v5.1.6  v5.1.7  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle               v1.21.1 v1.22.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                       v5.1.6  v5.1.7  A library to manipulate MIME messages
symfony/monolog-bridge             v5.1.6  v5.1.7  Symfony Monolog Bridge
symfony/monolog-bundle             v3.5.0  v3.6.0  Symfony MonologBundle
symfony/options-resolver           v4.4.14 v5.1.7  Symfony OptionsResolver Component
symfony/phpunit-bridge             v4.4.14 v5.1.7  Symfony PHPUnit Bridge
symfony/polyfill-intl-grapheme     v1.18.1 v1.20.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.18.1 v1.20.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.18.1 v1.20.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.18.1 v1.20.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.18.1 v1.20.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72             v1.18.1 v1.20.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.18.1 v1.20.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.18.1 v1.20.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                    v4.4.14 v5.1.7  Symfony Process Component
symfony/profiler-pack              v1.0.5  A pack for the Symfony web profiler
symfony/property-access            v5.1.6  v5.1.7  Symfony PropertyAccess Component
symfony/property-info              v5.1.6  v5.1.7  Symfony Property Info Component
symfony/routing                    v4.4.14 v5.1.7  Symfony Routing Component
symfony/security-acl               v3.1.0  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.14 v5.1.7  Symfony SecurityBundle
symfony/security-core              v4.4.14 v5.1.7  Symfony Security Component - Core Library
symfony/security-csrf              v5.1.6  v5.1.7  Symfony Security Component - CSRF Library
symfony/security-guard             v4.4.14 v5.1.7  Symfony Security Component - Guard
symfony/security-http              v4.4.14 v5.1.7  Symfony Security Component - HTTP Integration
symfony/serializer                 v5.1.6  v5.1.7  Symfony Serializer Component
symfony/serializer-pack            v1.0.3  v1.0.4  A pack for the Symfony serializer
symfony/service-contracts          v2.2.0  v2.2.0  Generic abstractions related to writing services
symfony/stopwatch                  v4.4.14 v5.1.7  Symfony Stopwatch Component
symfony/string                     v5.1.6  v5.1.7  Symfony String component
symfony/swiftmailer-bundle         v3.5.0  Symfony SwiftmailerBundle
symfony/templating                 v4.4.14 v5.1.7  Symfony Templating Component
symfony/test-pack                  v1.0.6  v1.0.7  A pack for functional and end-to-end testing within a Symfony app
symfony/translation                v4.4.14 v5.1.7  Symfony Translation Component
symfony/translation-contracts      v2.2.0  Generic abstractions related to translation
symfony/twig-bridge                v4.4.14 v5.1.7  Symfony Twig Bridge
symfony/twig-bundle                v4.4.14 v5.1.7  Symfony TwigBundle
symfony/validator                  v4.4.14 v5.1.7  Symfony Validator Component
symfony/var-dumper                 v5.1.6  v5.1.7  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v5.1.6  v5.1.7  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle        v5.0.11 v5.1.7  Symfony WebProfilerBundle
symfony/webpack-encore-bundle      v1.7.3  v1.7.3  Integration with your Symfony app & Webpack Encore!
symfony/workflow                   v4.4.14 v5.1.7  Symfony Workflow Component
symfony/yaml                       v4.4.14 v5.1.7  Symfony Yaml Component

PHP version

$ php -v
PHP 7.3.20

Subject

Translation key sonata_user_already_authenticated in flash message isn't translated anymore

Steps to reproduce

login once, then return on /login, flash message will appear with sonata_user_already_authenticated untranslated

Expected results

sonata_user_already_authenticated translated

Actual results

sonata_user_already_authenticated untranslated

Seems the problem is related to the fact that https://github.com/sonata-project/SonataUserBundle/blob/dac06cf40559192197f48a20bb0eb1dc19f87abb/src/Action/LoginAction.php#L94 does not translate the key. It may be related to this https://github.com/sonata-project/SonataAdminBundle/issues/6082 where something actually translated this key. So I don't know if we should inject Translator inside LoginAction to translate this key

VincentLanglet commented 3 years ago

Seems the problem is related to the fact that

https://github.com/sonata-project/SonataUserBundle/blob/dac06cf40559192197f48a20bb0eb1dc19f87abb/src/Action/LoginAction.php#L94

does not translate the key. It may be related to this sonata-project/SonataAdminBundle#6082 where something actually translated this key. So I don't know if we should inject Translator inside LoginAction to translate this key

I would say it's 100% related.

The code should be now

$this->session->getFlashBag()->add('sonata_user_error', $this->translator('sonata_user_already_authenticated', [], 'theRightDomain')); 

Could you provide a PR ?

mazsudo commented 3 years ago

thx for your reply @VincentLanglet. will do surely!