Skip to content

Feature: Allow processsing of multiple locales for translations #30

@leonhelmus

Description

@leonhelmus

When using the commands:

  • experius_missingtranslations:collect
  • experius_missingtranslations:existing-translations-to-database
  • experius_missingtranslations:missing-translations-to-database

It would save us a lot of time if we could add multiple locales instead of just one. I propose implementing the patch below.
This patch will allow us to add multiple locales. What do you think about this?

This patch is based on version experius/module-missingtranslations:4.0.1;

#
#
#

diff --git a/vendor/experius/module-missingtranslations/Console/Command/CollectMissingTranslationsCommand.php b/vendor/experius/module-missingtranslations/Console/Command/CollectMissingTranslationsCommand.php
--- a/vendor/experius/module-missingtranslations/Console/Command/CollectMissingTranslationsCommand.php
+++ b/vendor/experius/module-missingtranslations/Console/Command/CollectMissingTranslationsCommand.php	(date 1666614190782)
@@ -87,15 +87,20 @@
         $this->state->setAreaCode('frontend');
         $this->emulation->startEnvironmentEmulation($input->getOption(self::INPUT_KEY_STORE));

-        $fileName = $this->helper->getFileName($input->getOption(self::INPUT_KEY_LOCALE), false);
-        $generator->generate(
-            $directory,
-            $fileName,
-            $input->getOption(self::INPUT_KEY_MAGENTO),
-            $input->getOption(self::INPUT_KEY_LOCALE)
-        );
-        $this->emulation->stopEnvironmentEmulation();
-        $output->writeln('<info>Collected Missing Translations for specified store and stored in ' . $fileName . ' </info>');
+        $locales = explode(' ', $input->getOption(self::INPUT_KEY_LOCALE));
+        $magentoFlag = $input->getOption(self::INPUT_KEY_MAGENTO);
+
+        foreach ($locales as $locale) {
+            $fileName = $this->helper->getFileName($locale, false);
+            $generator->generate(
+                $directory,
+                $fileName,
+                $magentoFlag,
+                $locale
+            );
+            $output->writeln('<info>Collected Missing Translations for specified store and stored in ' . $fileName . ' </info>');
+        }
+        $this->emulation->stopEnvironmentEmulation();

         return Cli::RETURN_SUCCESS;
     }
@@ -124,7 +124,7 @@
                 self::INPUT_KEY_LOCALE,
                 self::SHORTCUT_KEY_LOCALE,
                 InputOption::VALUE_REQUIRED,
-                'Use the --locale parameter to parse specific language.'
+                'Use the --locale parameter to parse specific language. Separate multiple locales with a space.'
             ),
             new InputOption(
                 self::INPUT_KEY_STORE,

diff --git a/vendor/experius/module-missingtranslations/Console/Command/ExistingTranslationsToDatabase.php b/vendor/experius/module-missingtranslations/Console/Command/ExistingTranslationsToDatabase.php
--- a/vendor/experius/module-missingtranslations/Console/Command/ExistingTranslationsToDatabase.php
+++ b/vendor/experius/module-missingtranslations/Console/Command/ExistingTranslationsToDatabase.php
@@ -66,7 +66,7 @@
             throw new \InvalidArgumentException('Locale is not set. Please use --locale to set locale');
         }

-        $locale = $input->getOption(self::INPUT_KEY_LOCALE);
+        $locales = explode(' ', $input->getOption(self::INPUT_KEY_LOCALE));

         $global = false;
         if ($input->getOption(self::INPUT_KEY_GLOBAL)) {
@@ -82,15 +82,18 @@

         $output->writeln(
             'Inserting all existing csv translations into database for store id <info>' . $storeId
-            . '</info> and locale <info>' . $locale . '</info>'
+            . '</info> and locale(s) <info>' . $input->getOption(self::INPUT_KEY_LOCALE) . '</info>'
         );
         $output->writeln('Still working... One moment.');

-        $insertionCount = $this->translationCollector->updateTranslationDatabase(
-            (int)$storeId,
-            $locale,
-            TranslationCollector::TRANSLATION_TYPE_EXISTING
-        );
+        $insertionCount = 0;
+        foreach ($locales as $locale) {
+            $insertionCount += $this->translationCollector->updateTranslationDatabase(
+                (int)$storeId,
+                $locale,
+                \Experius\MissingTranslations\Model\TranslationCollector::TRANSLATION_TYPE_EXISTING
+            );
+        }

         if ($insertionCount > 0) {
             $output->writeln('Insertion was successful, <info>'
@@ -114,7 +114,7 @@
                 self::INPUT_KEY_LOCALE,
                 self::SHORTCUT_KEY_LOCALE,
                 InputOption::VALUE_REQUIRED,
-                'Use the --locale parameter to parse specific language.'
+                'Use the --locale parameter to parse specific language. Seperate multiple locales with a space.'
             ),
             new InputOption(
                 self::INPUT_KEY_GLOBAL,

diff --git a/vendor/experius/module-missingtranslations/Console/Command/MissingTranslationsToDatabase.php b/vendor/experius/module-missingtranslations/Console/Command/MissingTranslationsToDatabase.php
--- a/vendor/experius/module-missingtranslations/Console/Command/MissingTranslationsToDatabase.php
+++ b/vendor/experius/module-missingtranslations/Console/Command/MissingTranslationsToDatabase.php	(date 1666615735636)
@@ -66,7 +66,7 @@
             throw new \InvalidArgumentException('Locale is not set. Please use --locale to set locale');
         }

-        $locale = $input->getOption(self::INPUT_KEY_LOCALE);
+        $locales = explode(' ', $input->getOption(self::INPUT_KEY_LOCALE));

         $global = false;
         if ($input->getOption(self::INPUT_KEY_GLOBAL)) {
@@ -82,15 +82,18 @@

         $output->writeln(
             'Inserting all missing translations into database for store id <info>' . $storeId
-            . '</info> and locale <info>' . $locale . '</info>'
+            . '</info> and locale <info>' . $input->getOption(self::INPUT_KEY_LOCALE) . '</info>'
         );
         $output->writeln('Still working... One moment.');

-        $insertionCount = $this->translationCollector->updateTranslationDatabase(
-            (int)$storeId,
-            $locale,
-            TranslationCollector::TRANSLATION_TYPE_MISSING
-        );
+        $insertionCount = 0;
+        foreach ($locales as $locale) {
+            $insertionCount += $this->translationCollector->updateTranslationDatabase(
+                (int)$storeId,
+                $locale,
+                \Experius\MissingTranslations\Model\TranslationCollector::TRANSLATION_TYPE_MISSING
+            );
+        }

         if ($insertionCount > 0) {
             $output->writeln('Insertion was successful, <info>'
@@ -114,7 +117,7 @@
                 self::INPUT_KEY_LOCALE,
                 self::SHORTCUT_KEY_LOCALE,
                 InputOption::VALUE_REQUIRED,
-                'Use the --locale parameter to parse specific language.'
+                'Use the --locale parameter to parse specific language. Seperate multiple locales with a space.'
             ),
             new InputOption(
                 self::INPUT_KEY_GLOBAL,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions