I want to run a multi tenant Symfony (version 5.3) applications and for it I want to implement a custom translation file loader.
According to the Symfony documentation it should be very easy: https://symfony.com/doc/current/reference/dic_tags.html#dic-tags-translation-loader
However, it is not working for me. I have added the class and tag to the services.
App\Translation\ProjectYamlLoader:
tags:
- { name: translation.loader, alias: yaml }
And this is the Loader file
<?php
namespace App\Translation;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\LogicException;
use Symfony\Component\Translation\Loader\FileLoader;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser as YamlParser;
use Symfony\Component\Yaml\Yaml;
/**
* YamlFileLoader loads translations from Yaml files.
*
*/
class ProjectYamlLoader extends FileLoader
{
private $yamlParser;
/**
* {@inheritdoc}
*/
protected function loadResource($resource)
{
$die->here();
if (null === $this->yamlParser) {
if (!class_exists(\Symfony\Component\Yaml\Parser::class)) {
throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
}
$this->yamlParser = new YamlParser();
}
try {
$messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('The file "%s" does not contain valid YAML: ', $resource).$e->getMessage(), 0, $e);
}
if (null !== $messages && !\is_array($messages)) {
throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource));
}
return $messages ?: [];
}
}
My functionality wasn't working so I added the $die->here();
for debug puropses. I am now sure the class is not called, because there is no error throw.
What did I miss? Why is this not working?
source https://stackoverflow.com/questions/67909884/symfony-5-3-custom-fileloader-not-working
No comments:
Post a Comment