lexik / LexikTranslationBundle

This Symfony bundle allow to import translation files content into the database and provide a GUI to edit translations.
MIT License
419 stars 255 forks source link

ImportTranslationsCommand: undefined method named "getFormats" #451

Open nicodemuz opened 6 months ago

nicodemuz commented 6 months ago

Using Symfony 6.4:

*** Importing application translation files ***
*** Using dir /path/to/symfony/translations to lookup translation files. ***
07:36:31 CRITICAL  [console] Error thrown while running command "--env=prod lexik:translations:import --cache-clear --locales=en --domains='app,email,validators'". Message: "Call to undefined method Symfony\Bundle\FrameworkBundle\Translation\Translator::getFormats()" ["exception" => Error { …},"command" => "--env=prod lexik:translations:import --cache-clear --locales=en --domains='app,email,validators'","message" => "Call to undefined method Symfony\Bundle\FrameworkBundle\Translation\Translator::getFormats()"]

In ImportTranslationsCommand.php line 334:

  Attempted to call an undefined method named "getFormats" of class "Symfony\Bundle\FrameworkBundle\Translation\Translator".

lexik:translations:import [-c|--cache-clear] [-f|--force] [-g|--globals] [-l|--locales LOCALES] [-d|--domains [DOMAINS]] [-i|--case-insensitive] [-m|--merge] [-p|--import-path IMPORT-PATH] [-o|--only-vendors] [--] [<bundle>]
bartmcleod commented 6 months ago

@nicodemuz Use dev-6.0 in composer

bartmcleod commented 6 months ago

But I doubt if that will fix it, as the new SF 7 changes are not yet in master anyway, as far as I know, so they can not have broken your installation. What if an update to the translation bundle caused this and you need to pin it on an earlier release @nicodemuz ?

nicodemuz commented 6 months ago

It seems to happen only if LexikTranslationBundle is loaded before FrameworkBundle in bundles.php:

    Lexik\Bundle\TranslationBundle\LexikTranslationBundle::class => ['all' => true],
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],

Swapping the order seems to fix the issue.

I had originally swapped the order of bundles in bundles.php because of this issue: https://github.com/lexik/LexikTranslationBundle/issues/440