Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions EventDispatcher/CleanTranslationCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CleanTranslationCacheListener
public function __construct(
private readonly StorageInterface $storage,
private readonly TranslatorInterface $translator,
private readonly string$cacheDirectory,
private readonly string $cacheDirectory,
private readonly LocaleManagerInterface $localeManager,
private readonly int $cacheInterval,
) {
Expand All @@ -36,7 +36,10 @@ public function onKernelRequest(RequestEvent $event)
->date('< '.$lastUpdateTime->format('Y-m-d H:i:s'));

if ($finder->count() > 0) {
$this->translator->removeLocalesCacheFiles($this->localeManager->getLocales());
// Use TranslatorDecorator if available, otherwise skip
if (method_exists($this->translator, 'removeLocalesCacheFiles')) {
$this->translator->removeLocalesCacheFiles($this->localeManager->getLocales());
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Form/Handler/TransUnitFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@
use Lexik\Bundle\TranslationBundle\Manager\FileInterface;
use Lexik\Bundle\TranslationBundle\Manager\FileManagerInterface;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* @author CΓ©dric Girard <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.form.handler.trans_unit', public: true)]
class TransUnitFormHandler implements FormHandlerInterface
{
/**
* @param string $rootDir
*/
public function __construct(
#[Autowire(service: 'lexik_translation.trans_unit.manager')]
protected TransUnitManagerInterface $transUnitManager,
#[Autowire(service: 'lexik_translation.file.manager')]
protected FileManagerInterface $fileManager,
#[Autowire(service: 'lexik_translation.translation_storage')]
protected StorageInterface $storage,
#[Autowire(service: 'Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface')]
protected LocaleManagerInterface $localeManager,
#[Autowire('%kernel.project_dir%')]
protected string $rootDir,
) {
}
Expand Down
5 changes: 5 additions & 0 deletions Manager/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Lexik\Bundle\TranslationBundle\Manager;

use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Manager for translations files.
*
* @author CΓ©dric Girard <[email protected]>
* @author Nikola Petkanski <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.file.manager')]
class FileManager implements FileManagerInterface
{
/**
Expand All @@ -18,7 +21,9 @@ class FileManager implements FileManagerInterface
* @param string $rootDir
*/
public function __construct(
#[Autowire(service: 'lexik_translation.translation_storage')]
private readonly StorageInterface $storage,
#[Autowire('%kernel.project_dir%')]
private $rootDir,
) {
}
Expand Down
5 changes: 5 additions & 0 deletions Manager/LocaleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace Lexik\Bundle\TranslationBundle\Manager;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Manager for translations files.
*/
#[AsAlias(id: 'lexik_translation.locale.manager', public: true)]
class LocaleManager implements LocaleManagerInterface
{
/**
* Constructor
*/
public function __construct(
#[Autowire('%lexik_translation.managed_locales%')]
protected array $managedLocales
) {
}
Expand Down
6 changes: 6 additions & 0 deletions Manager/TransUnitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
use Lexik\Bundle\TranslationBundle\Model\Translation;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Lexik\Bundle\TranslationBundle\Storage\PropelStorage;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Class to manage TransUnit entities or documents.
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.trans_unit.manager', public: true)]
class TransUnitManager implements TransUnitManagerInterface
{
public function __construct(
#[Autowire(service: 'lexik_translation.translation_storage')]
private readonly StorageInterface $storage,
#[Autowire(service: 'lexik_translation.file.manager')]
private readonly FileManagerInterface $fileManager,
#[Autowire('%kernel.project_dir%')]
private readonly string $kernelRootDir,
) {
}
Expand Down
18 changes: 15 additions & 3 deletions Storage/Listener/DoctrineORMListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
foreach ($metadata->getFieldNames() as $name) {
$fieldMapping = $metadata->getFieldMapping($name);

if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
$fieldMapping['length'] = 191;
$metadata->fieldMappings[$name] = $fieldMapping;
// Use properties instead of ArrayAccess for Doctrine ORM 3.0+ compatibility
// FieldMapping is now an object with properties, not an array
// Check if it's an array (legacy) or object (Doctrine ORM 3.0+)
if (is_array($fieldMapping)) {
// Legacy array format (for backward compatibility with Doctrine ORM 2.x)
if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
$fieldMapping['length'] = 191;
$metadata->fieldMappings[$name] = $fieldMapping;
}
} else {
// Object format (Doctrine ORM 3.0+) - use properties directly
if (isset($fieldMapping->type) && 'string' === $fieldMapping->type) {
$fieldMapping->length = 191;
$metadata->fieldMappings[$name] = $fieldMapping;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Translation/Exporter/ExporterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Lexik\Bundle\TranslationBundle\Translation\Exporter;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;

/**
* Exporter collector.
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.exporter_collector', public: true)]
class ExporterCollector
{
/**
Expand Down
7 changes: 7 additions & 0 deletions Translation/Exporter/JsonExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

namespace Lexik\Bundle\TranslationBundle\Translation\Exporter;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Export translations to a Json file.
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsTaggedItem('lexik_translation.exporter', alias: 'json')]
#[AsAlias(id: 'lexik_translation.exporter.json', public: true)]
class JsonExporter implements ExporterInterface
{
/**
* @param bool $hierarchicalFormat
*/
public function __construct(
#[Autowire('%lexik_translation.exporter.json.hierarchical_format%')]
private $hierarchicalFormat = false
) {
}
Expand Down
5 changes: 5 additions & 0 deletions Translation/Exporter/PhpExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Lexik\Bundle\TranslationBundle\Translation\Exporter;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;

/**
* Export translations to a PHP file.
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsTaggedItem('lexik_translation.exporter', alias: 'php')]
#[AsAlias(id: 'lexik_translation.exporter.php')]
class PhpExporter implements ExporterInterface
{
/**
Expand Down
5 changes: 5 additions & 0 deletions Translation/Exporter/XliffExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Lexik\Bundle\TranslationBundle\Translation\Exporter;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;

/**
* Export translations to a Xliff file.
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsTaggedItem('lexik_translation.exporter', alias: 'xlf')]
#[AsAlias(id: 'lexik_translation.exporter.xliff', public: true)]
class XliffExporter implements ExporterInterface
{
/**
Expand Down
6 changes: 6 additions & 0 deletions Translation/Exporter/YamlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Lexik\Bundle\TranslationBundle\Translation\Exporter;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Yaml\Dumper;

/**
Expand All @@ -10,9 +13,12 @@
* @author CΓ©dric Girard <[email protected]>
* @author Tobias Nyholm <[email protected]>
*/
#[AsTaggedItem('lexik_translation.exporter', alias: 'yml')]
#[AsAlias(id: 'lexik_translation.exporter.yml')]
class YamlExporter implements ExporterInterface
{
public function __construct(
#[Autowire('%lexik_translation.exporter.yml.use_tree%')]
private readonly bool $createTree = false
) {
}
Expand Down
6 changes: 6 additions & 0 deletions Translation/Loader/DatabaseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Lexik\Bundle\TranslationBundle\Translation\Loader;

use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\MessageCatalogue;

Expand All @@ -11,12 +14,15 @@
*
* @author CΓ©dric Girard <[email protected]>
*/
#[AsTaggedItem('translation.loader', alias: 'database')]
#[AsAlias(id: 'Lexik\Bundle\TranslationBundle\Translation\Loader')]
class DatabaseLoader implements LoaderInterface
{
/**
* Construct.
*/
public function __construct(
#[Autowire(service: 'lexik_translation.translation_storage')]
private readonly StorageInterface $storage,
) {
}
Expand Down
11 changes: 9 additions & 2 deletions Util/DataGrid/DataGridFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

use Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\JsonResponse;
use Lexik\Bundle\TranslationBundle\Manager\TransUnitInterface;

/**
* @author CΓ©dric Girard <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.data_grid.formatter', public: true)]
class DataGridFormatter
{
/**
* Constructor.
*
* @param string $storage
*/
public function __construct(protected LocaleManagerInterface $localeManager, protected $storage)
{
public function __construct(
#[Autowire(service: 'Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface')]
protected LocaleManagerInterface $localeManager,
#[Autowire('%lexik_translation.storage.type%')]
protected $storage
) {
}

/**
Expand Down
35 changes: 30 additions & 5 deletions Util/DataGrid/DataGridRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Lexik\Bundle\TranslationBundle\Manager\TransUnitManagerInterface;
use Lexik\Bundle\TranslationBundle\Model\TransUnit;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profile;
Expand All @@ -18,6 +20,7 @@
/**
* @author CΓ©dric Girard <[email protected]>
*/
#[AsAlias(id: 'lexik_translation.data_grid.request_handler', public: true)]
class DataGridRequestHandler
{
/**
Expand All @@ -35,8 +38,16 @@ class DataGridRequestHandler
*/
protected $defaultFileFormat;

public function __construct(protected TransUnitManagerInterface $transUnitManager, protected FileManagerInterface $fileManager, protected StorageInterface $storage, protected LocaleManagerInterface $localeManager)
{
public function __construct(
#[Autowire(service: 'lexik_translation.trans_unit.manager')]
protected TransUnitManagerInterface $transUnitManager,
#[Autowire(service: 'lexik_translation.file.manager')]
protected FileManagerInterface $fileManager,
#[Autowire(service: 'lexik_translation.translation_storage')]
protected StorageInterface $storage,
#[Autowire(service: 'Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface')]
protected LocaleManagerInterface $localeManager
) {
$this->createMissing = false;
$this->defaultFileFormat = 'yml';
}
Expand Down Expand Up @@ -250,10 +261,24 @@ protected function fixParameters(array $dirtyParameters)

array_walk($dirtyParameters, function ($value, $key) use (&$parameters) {
if ($key != '_search') {
$key = trim($key, '_');
$value = trim($value, '_');
// Handle nested filter arrays: filter[_domain] => ['_domain' => 'value']
if ($key === 'filter' && is_array($value)) {
foreach ($value as $filterKey => $filterValue) {
// filterKey might be like '_domain', filterValue is the actual value
$cleanKey = is_string($filterKey) ? trim($filterKey, '_') : $filterKey;
$cleanValue = is_string($filterValue) ? trim($filterValue, '_') : $filterValue;
$parameters[$cleanKey] = $cleanValue;
}
} else {
// Handle regular parameters
$cleanKey = is_string($key) ? trim($key, '_') : $key;
$cleanValue = is_string($value) ? trim($value, '_') : $value;
$parameters[$cleanKey] = $cleanValue;
}
} else {
// Keep _search as is
$parameters[$key] = $value;
}
$parameters[$key] = $value;
});

return $parameters;
Expand Down
5 changes: 5 additions & 0 deletions Util/Overview/StatsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

use Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Class StatsAggregator
* @package Lexik\Bundle\TranslationBundle\Util\Overview
*/
#[AsAlias(id: 'lexik_translation.overview.stats_aggregator', public: true)]
class StatsAggregator
{
public function __construct(
#[Autowire(service: 'lexik_translation.translation_storage')]
private readonly StorageInterface $storage,
#[Autowire(service: 'Lexik\Bundle\TranslationBundle\Manager\LocaleManagerInterface')]
private readonly LocaleManagerInterface $localeManager,
) {
}
Expand Down
Loading