diff --git a/Command/ExportTranslationsCommand.php b/Command/ExportTranslationsCommand.php
index c5bb6c2f..13eedbbd 100644
--- a/Command/ExportTranslationsCommand.php
+++ b/Command/ExportTranslationsCommand.php
@@ -2,14 +2,15 @@
namespace Lexik\Bundle\TranslationBundle\Command;
+use Lexik\Bundle\TranslationBundle\Manager\FileInterface;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
-use Lexik\Bundle\TranslationBundle\Translation\Translator;
+use Lexik\Bundle\TranslationBundle\Translation\Exporter\ExporterCollector;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Lexik\Bundle\TranslationBundle\Manager\FileInterface;
use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Export translations from the database in to files.
@@ -18,22 +19,28 @@
*/
class ExportTranslationsCommand extends Command
{
- /**
- * @var InputInterface
- */
- private $input;
-
- /**
- * @var OutputInterface
- */
- private $output;
+ private InputInterface $input;
+ private OutputInterface $output;
private StorageInterface $storage;
- private Translator $translator;
+ private TranslatorInterface $translator;
+ private string $projectDir;
+ private Filesystem $fileSystem;
+ private ExporterCollector $exporterCollector;
+
+ public function __construct(
+ StorageInterface $storage,
+ TranslatorInterface $translator,
+ FileSystem $fileSystem,
+ ExporterCollector $exporterCollector,
+ string $projectDir
+ ) {
+ parent::__construct();
- public function __construct(StorageInterface $storage, Translator $translator)
- {
$this->storage = $storage;
$this->translator = $translator;
+ $this->projectDir = $projectDir;
+ $this->fileSystem = $fileSystem;
+ $this->exporterCollector = $exporterCollector;
}
/**
@@ -44,10 +51,13 @@ protected function configure()
$this->setName('lexik:translations:export');
$this->setDescription('Export translations from the database to files.');
- $this->addOption('locales', 'l', InputOption::VALUE_OPTIONAL, 'Only export files for given locales. e.g. "--locales=en,de"', null);
- $this->addOption('domains', 'd', InputOption::VALUE_OPTIONAL, 'Only export files for given domains. e.g. "--domains=messages,validators"', null);
+ $this->addOption('locales', 'l', InputOption::VALUE_OPTIONAL,
+ 'Only export files for given locales. e.g. "--locales=en,de"', null);
+ $this->addOption('domains', 'd', InputOption::VALUE_OPTIONAL,
+ 'Only export files for given domains. e.g. "--domains=messages,validators"', null);
$this->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'Force the output format.', null);
- $this->addOption('override', 'o', InputOption::VALUE_NONE, 'Only export modified phrases (app/Resources/translations are exported fully anyway)');
+ $this->addOption('override', 'o', InputOption::VALUE_NONE,
+ 'Only export modified phrases (app/Resources/translations are exported fully anyway)');
$this->addOption('export-path', 'p', InputOption::VALUE_REQUIRED, 'Export files to given path.');
}
@@ -65,9 +75,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($filesToExport as $file) {
$this->exportFile($file);
}
- } else {
- $this->output->writeln('No translation\'s files in the database.');
+
+ return 0;
}
+
+ $this->output->writeln('No translation\'s files in the database.');
+
+ return 1;
}
/**
@@ -77,12 +91,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getFilesToExport()
{
- $locales = $this->input->getOption('locales') ? explode(',', $this->input->getOption('locales')) : array();
- $domains = $this->input->getOption('domains') ? explode(',', $this->input->getOption('domains')) : array();
+ $locales = $this->input->getOption('locales') ? explode(',', $this->input->getOption('locales')) : [];
+ $domains = $this->input->getOption('domains') ? explode(',', $this->input->getOption('domains')) : [];
- return $this->getContainer()
- ->get('lexik_translation.translation_storage')
- ->getFilesByLocalesAndDomains($locales, $domains);
+ return $this->storage->getFilesByLocalesAndDomains($locales, $domains);
}
/**
@@ -92,7 +104,7 @@ protected function getFilesToExport()
*/
protected function exportFile(FileInterface $file)
{
- $rootDir = $this->input->getOption('export-path') ? $this->input->getOption('export-path') . '/' : $this->getContainer()->getParameter('kernel.project_dir');
+ $rootDir = $this->input->getOption('export-path') ? $this->input->getOption('export-path') . '/' : $this->projectDir;
$this->output->writeln(sprintf('# Exporting "%s/%s":', $file->getPath(), $file->getName()));
$override = $this->input->getOption('override');
@@ -129,10 +141,8 @@ protected function exportFile(FileInterface $file)
// ensure the path exists
if ($this->input->getOption('export-path')) {
- /** @var Filesystem $fs */
- $fs = $this->getContainer()->get('filesystem');
- if (!$fs->exists($outputPath)) {
- $fs->mkdir($outputPath);
+ if (!$this->fileSystem->exists($outputPath)) {
+ $this->fileSystem->mkdir($outputPath);
}
}
@@ -147,15 +157,15 @@ protected function exportFile(FileInterface $file)
* If the output file exists we merge existing translations with those from the database.
*
* @param FileInterface $file
- * @param string $outputFile
- * @param array $translations
+ * @param string $outputFile
+ * @param array $translations
* @return array
*/
protected function mergeExistingTranslations($file, $outputFile, $translations)
{
if (file_exists($outputFile)) {
$extension = pathinfo($outputFile, PATHINFO_EXTENSION);
- $loader = $this->getContainer()->get('lexik_translation.translator')->getLoader($extension);
+ $loader = $this->translator->getLoader($extension);
$messageCatalogue = $loader->load($outputFile, $file->getLocale(), $file->getDomain());
$translations = array_merge($messageCatalogue->all($file->getDomain()), $translations);
@@ -168,7 +178,7 @@ protected function mergeExistingTranslations($file, $outputFile, $translations)
* Export translations.
*
* @param string $outputFile
- * @param array $translations
+ * @param array $translations
* @param string $format
*/
protected function doExport($outputFile, $translations, $format)
@@ -177,7 +187,7 @@ protected function doExport($outputFile, $translations, $format)
$this->output->write(sprintf('%d translations to export: ', count($translations)));
try {
- $exported = $this->getContainer()->get('lexik_translation.exporter_collector')->export(
+ $exported = $this->exporterCollector->export(
$format,
$outputFile,
$translations
diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php
index caebea54..b8fdb6c8 100644
--- a/Command/ImportTranslationsCommand.php
+++ b/Command/ImportTranslationsCommand.php
@@ -4,7 +4,6 @@
use Lexik\Bundle\TranslationBundle\Manager\LocaleManager;
use Lexik\Bundle\TranslationBundle\Translation\Importer\FileImporter;
-use Lexik\Bundle\TranslationBundle\Translation\Translator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -13,6 +12,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Imports translation files content in the database.
@@ -23,16 +23,16 @@
*/
class ImportTranslationsCommand extends Command
{
- private Translator $translator;
+ private TranslatorInterface $translator;
private LocaleManager $localeManager;
private FileImporter $fileImporter;
/**
- * @param Translator $translator
+ * @param TranslatorInterface $translator
*/
public function __construct(
- Translator $translator,
+ TranslatorInterface $translator,
LocaleManager $localeManager,
FileImporter $fileImporter
)
@@ -299,7 +299,7 @@ protected function findTranslationsFiles($path, array $locales, array $domains,
}
if (true === $autocompletePath) {
- $dir = (0 === strpos($path, $this->getApplication()->getKernel()->getRootDir() . '/Resources')) ? $path : $path . '/Resources/translations';
+ $dir = (0 === strpos($path, $this->getApplication()->getKernel()->getProjectDir() . '/Resources')) ? $path : $path . '/Resources/translations';
} else {
$dir = $path;
}
diff --git a/Controller/RestController.php b/Controller/RestController.php
index 8ef83bfd..1d3d985c 100644
--- a/Controller/RestController.php
+++ b/Controller/RestController.php
@@ -3,14 +3,14 @@
namespace Lexik\Bundle\TranslationBundle\Controller;
use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* @author Cédric Girard
*/
-class RestController extends Controller
+class RestController extends AbstractController
{
use CsrfCheckerTrait;
@@ -21,7 +21,7 @@ class RestController extends Controller
*/
public function listAction(Request $request)
{
- list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPage($request);
+ [$transUnits, $count] = $this->get('lexik_translation.data_grid.request_handler')->getPage($request);
return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
}
@@ -34,7 +34,7 @@ public function listAction(Request $request)
*/
public function listByProfileAction(Request $request, $token)
{
- list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPageByToken($request, $token);
+ [$transUnits, $count] = $this->get('lexik_translation.data_grid.request_handler')->getPageByToken($request, $token);
return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
}
diff --git a/Controller/TranslationController.php b/Controller/TranslationController.php
index 10f53617..6d89e8cf 100644
--- a/Controller/TranslationController.php
+++ b/Controller/TranslationController.php
@@ -5,14 +5,14 @@
use Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* @author Cédric Girard
*/
-class TranslationController extends Controller
+class TranslationController extends AbstractController
{
use CsrfCheckerTrait;
diff --git a/DependencyInjection/Compiler/TranslatorPass.php b/DependencyInjection/Compiler/TranslatorPass.php
index e3698b4a..8cb5780f 100644
--- a/DependencyInjection/Compiler/TranslatorPass.php
+++ b/DependencyInjection/Compiler/TranslatorPass.php
@@ -47,8 +47,8 @@ public function process(ContainerBuilder $container)
}
}
- if ($container->hasDefinition('lexik_translation.importer.file')) {
- $container->findDefinition('lexik_translation.importer.file')->replaceArgument(0, $loadersReferences);
+ if ($container->hasDefinition('Lexik\Bundle\TranslationBundle\Translation\Importer\FileImporter')) {
+ $container->findDefinition('Lexik\Bundle\TranslationBundle\Translation\Importer\FileImporter')->replaceArgument(0, $loadersReferences);
}
// exporters
diff --git a/Resources/config/routing/api.yml b/Resources/config/routing/api.yml
index 742ddd24..600e3945 100644
--- a/Resources/config/routing/api.yml
+++ b/Resources/config/routing/api.yml
@@ -1,24 +1,24 @@
lexik_translation_list:
path: /translations
- defaults: { _controller: "LexikTranslationBundle:Rest:list" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\RestController:listAction' }
methods: [GET]
lexik_translation_profiler:
path: /translations/profiler/{token}
- defaults: { _controller: "LexikTranslationBundle:Rest:listByProfile" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\RestController:listByProfileAction' }
methods: [GET]
lexik_translation_update:
path: /translations/{id}
- defaults: { _controller: "LexikTranslationBundle:Rest:update" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\RestController:updateAction' }
methods: [PUT]
lexik_translation_delete_locale:
path: /translations/{id}/{locale}
- defaults: { _controller: "LexikTranslationBundle:Rest:deleteTranslation" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\RestController:deleteTranslationAction' }
methods: [DELETE]
lexik_translation_delete:
path: /translations/{id}
- defaults: { _controller: "LexikTranslationBundle:Rest:delete" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\RestController:deleteAction' }
methods: [DELETE]
diff --git a/Resources/config/routing/app.yml b/Resources/config/routing/app.yml
index eade7199..3308d289 100644
--- a/Resources/config/routing/app.yml
+++ b/Resources/config/routing/app.yml
@@ -1,19 +1,19 @@
lexik_translation_overview:
path: /
- defaults: { _controller: "LexikTranslationBundle:Translation:overview" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\TranslationController:overviewAction' }
methods: [GET]
lexik_translation_grid:
path: /grid
- defaults: { _controller: "LexikTranslationBundle:Translation:grid" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\TranslationController:gridAction' }
methods: [GET]
lexik_translation_new:
path: /new
- defaults: { _controller: "LexikTranslationBundle:Translation:new" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\TranslationController:newAction' }
methods: [GET, POST]
lexik_translation_invalidate_cache:
path: /invalidate-cache
- defaults: { _controller: "LexikTranslationBundle:Translation:invalidateCache" }
+ defaults: { _controller: 'Lexik\Bundle\TranslationBundle\Controller\TranslationController:invalidateCacheAction' }
methods: [GET]
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index 8391a2c2..b1c4d1e7 100644
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -48,6 +48,9 @@
Lexik\Bundle\TranslationBundle\Command\ImportTranslationsCommand
Lexik\Bundle\TranslationBundle\Command\ExportTranslationsCommand
+ Lexik\Bundle\TranslationBundle\Controller\TranslationController
+ Lexik\Bundle\TranslationBundle\Controller\RestController
+
false
15
@@ -58,12 +61,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
@@ -76,12 +97,13 @@
%kernel.project_dir%
-
+
%lexik_translation.managed_locales%
+
-
+
@@ -90,9 +112,10 @@
%lexik_translation.importer.case_insensitive%
-
+
-
+
+
@@ -154,14 +177,14 @@
-
-
+
-
+
+ %kernel.project_dir%
-
+
diff --git a/Translation/Importer/FileImporter.php b/Translation/Importer/FileImporter.php
index d29c0c54..8756afba 100644
--- a/Translation/Importer/FileImporter.php
+++ b/Translation/Importer/FileImporter.php
@@ -93,13 +93,13 @@ public function import(\Symfony\Component\Finder\SplFileInfo $file, $forceUpdate
{
$this->skippedKeys = array();
$imported = 0;
- list($domain, $locale, $extention) = explode('.', $file->getFilename());
+ list($domain, $locale, $extension) = explode('.', $file->getFilename());
- if (!isset($this->loaders[$extention])) {
- throw new \RuntimeException(sprintf('No load found for "%s" format.', $extention));
+ if (!isset($this->loaders[$extension])) {
+ throw new \RuntimeException(sprintf('No loader found for "%s" format.', $extension));
}
- $messageCatalogue = $this->loaders[$extention]->load($file->getPathname(), $locale, $domain);
+ $messageCatalogue = $this->loaders[$extension]->load($file->getPathname(), $locale, $domain);
$translationFile = $this->fileManager->getFor($file->getFilename(), $file->getPath());
diff --git a/composer.json b/composer.json
index 2b5a5be5..d3774437 100644
--- a/composer.json
+++ b/composer.json
@@ -17,11 +17,12 @@
}
],
"require": {
- "php": "^7.4"
+ "php": "^7.4",
+ "symfony/framework-bundle": "~4.0|~5.0"
},
"require-dev": {
- "symfony/symfony": "~5.0",
"ext-mongodb": "*",
+ "symfony/symfony": "~5.0",
"doctrine/orm": ">=2.4",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/data-fixtures": "~1.1",