schmittjoh / JMSTranslationBundle

Puts the Symfony2 Translation Component on steroids
http://jmsyst.com/bundles/JMSTranslationBundle
426 stars 292 forks source link

The format "yml" does not exist #468

Closed tristanbes closed 6 years ago

tristanbes commented 6 years ago
Q A
Bundle version
Symfony version 3.4
PHP version 7.1

Hi,

Having 100% of .xliff files in Resources/translations adding one example.fr.yml inside Resources/translations and the bundle stops working:

The format "yml" does not exist.

jms_translation:
    configs:
        app:
            dirs: ["%kernel.root_dir%", "%kernel.root_dir%/../src/AppBundle"]
            output_dir: "%kernel.root_dir%/Resources/translations"
            ignored_domains: [routes, example]
            excluded_names: ["*TestCase.php", "*Test.php"]
            excluded_dirs: [cache, data, logs]
emr commented 6 years ago

the problem is not related to .yml or .xliff format. but I don't understand the problem what related backup your translation data and delete app/Resources/translations folder. fixed for me

https://github.com/schmittjoh/JMSI18nRoutingBundle/issues/212

tristanbes commented 6 years ago

I don't understand the process.

I moved all files from translations/ to another folder, run the command, which did fine, then replace my files and re-run the command and I got the same error.

The only way I found is to move the .yml files outside the translations folder just the time to run the command, and move them back, but it's ANNOYING. :-)

emr commented 6 years ago

absolutely...

@schmittjoh must be interested in this issue

bocharsky-bw commented 6 years ago

Try to rename your translations to .yaml instead of .yml, it helped me to get rid of this message

lordjancso commented 6 years ago

@bocharsky-bw actually it helped me. :)

soullivaneuh commented 6 years ago

Please see #479.

Waiting the merge and release, you can make a workaround by creating a compiler pass like this:

namespace AppBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class TranslationLoaderPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $loaderManagerDefinition = $container->getDefinition('jms_translation.loader_manager');
        $loaders = $loaderManagerDefinition->getArgument(0);
        $loaders['yml'] = $loaders['yaml'];
        $loaderManagerDefinition->replaceArgument(0, $loaders);
    }
}

And then register it:

namespace AppBundle;

use AppBundle\DependencyInjection\Compiler\TranslationLoaderPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class AppBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container
            ->addCompilerPass(new TranslationLoaderPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1)
        ;
    }
}

The -1 priority is important! This pass must be called after the vendor one to have the loaders list.

ohvitorino commented 6 years ago

@Soullivaneuh your compiler pass seems to work for me. Thanks!