From: Vincent Vanwaelscappel Date: Wed, 28 Jul 2021 14:38:14 +0000 (+0200) Subject: wip #4623 @0..25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d28438d2588fec4e84e220af07849466d12528b3;p=cubist_cms-back.git wip #4623 @0..25 --- diff --git a/src/app/Magic/Models/Translate.php b/src/app/Magic/Models/Translate.php index 252e63b..ecab8b1 100644 --- a/src/app/Magic/Models/Translate.php +++ b/src/app/Magic/Models/Translate.php @@ -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]); + } } }