]> _ Git - cubist_cms-back.git/commitdiff
wip #4623 @0..25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 14:38:14 +0000 (16:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Jul 2021 14:38:14 +0000 (16:38 +0200)
src/app/Magic/Models/Translate.php

index 252e63b5b40bd5e33bc78b071e3b06d144d32e9f..ecab8b112b7111ff56a50d615432d74637bd42ca 100644 (file)
@@ -29,8 +29,8 @@ class Translate extends CubistMagicTranslatableModel
         $paths = $this->getPaths();
         $translate = new \Cubist\Locale\Translate();
         $translate->setExtensions($this->getExtensions());
-        foreach ($paths as $path) {
-            $translate->addPath(base_path() . '/' . $path);
+        foreach ($paths as $sectionLabel => $path) {
+            $translate->addPath(base_path() . '/' . $path, $sectionLabel);
         }
 
         $translate->parseFiles();
@@ -44,15 +44,34 @@ class Translate extends CubistMagicTranslatableModel
             'value' => '-',
             'fake' => true]);
 
-        foreach ($translate->getStringToTranslate() as $string) {
-            $key = 't_' . base64_encode($string);
+        $seenStrings = [];
 
-            $this->addField(['name' => $key,
-                'label' => e($string),
-                'type' => 'Textarea',
-                'translatable' => true,
-                'store_in' => 'content',
-                'fake' => true]);
+        foreach ($translate->getStringToTranslate() as $sectionLabel => $strings) {
+            $toTranslate = [];
+            foreach ($strings as $string) {
+                if (isset($seenStrings[$string])) {
+                    continue;
+                }
+                $toTranslate[] = $string;
+                $seenStrings[$string] = true;
+            }
+            if (!count($toTranslate)) {
+                continue;
+            }
+            if (!is_numeric($sectionLabel)) {
+                $this->addField($sectionLabel, 'FormSection', $sectionLabel);
+            }
+
+            foreach ($toTranslate as $string) {
+                $key = 't_' . base64_encode($string);
+
+                $this->addField(['name' => $key,
+                    'label' => e($string),
+                    'type' => 'Textarea',
+                    'translatable' => true,
+                    'store_in' => 'content',
+                    'fake' => true]);
+            }
         }
     }