From: Vincent Vanwaelscappel Date: Wed, 5 Jun 2024 15:58:07 +0000 (+0200) Subject: wip #6946 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=dbaf66780d5695bbc905876accc4df02a55bc01f;p=fluidbook-toolbox.git wip #6946 @1 --- diff --git a/app/Fields/Webflow/WebflowPage.php b/app/Fields/Webflow/WebflowPage.php new file mode 100644 index 000000000..ff8f36db3 --- /dev/null +++ b/app/Fields/Webflow/WebflowPage.php @@ -0,0 +1,10 @@ +addField('texts', WebflowTexts::class, '', ['tab' => __('Textes'), 'translatable' => true, 'hint' => __('Modifier un texte ici ne produira aucun changement sur webflow')]); $this->addField('images', WebflowImages::class, '', ['tab' => __('Images'), 'translatable' => true]); $this->addField('seo', BunchOfFieldsMultiple::class, '', ['translatable' => true, 'edit_label' => '%url | %seo_title', 'allows_add' => false, 'allows_delete' => false, 'allows_clone' => false, 'allows_reorder' => false, 'bunch' => SEOPage::class, 'tab' => __('SEO')]); + $this->addField('redirections', BunchOfFieldsMultiple::class, '', ['translatable' => false, 'bunch' => Redirection::class, 'tab' => __('Redirections')]); $this->addField('api', Hidden::class); } @@ -177,26 +179,42 @@ class ToolWebflow extends ToolboxTranslatableModel $mainLocale = $this->getMainLocale(); $locales = $this->getLocalesCodes(); - $props = ['seo']; - foreach ($props as $prop) { - $data = Json::decode($this->$prop, Json::TYPE_ARRAY); - $data[$mainLocale] = $this->api[$prop]; - foreach ($locales as $locale) { - if ($locale === $mainLocale) { - continue; - } - if (!isset($data[$locale])) { - $data[$locale] = []; + Api::setCache(Files::mkdir(protected_path('cache/azure_translate'))); + $translateAPI = new Api(env('AZURE_TRANSLATE_API_KEY')); + + $data = Json::decode($this->seo, Json::TYPE_ARRAY); + $data[$mainLocale] = $this->api['seo']; + $seoTranslateProps = ['og_title', 'og_description', 'seo_title', 'seo_description']; + foreach ($locales as $locale) { + if ($locale === $mainLocale) { + continue; + } + if (!isset($data[$locale])) { + $data[$locale] = []; + } + foreach ($data[$mainLocale] as $d) { + $found = false; + foreach ($data[$locale] as $l) { + if ($d['id'] == $l['id']) { + $found = $l; + break; + } } - foreach ($data[$mainLocale] as $d) { - $data[$locale][] = $d; + if (!$found) { + $t = $d; + foreach ($seoTranslateProps as $seoTranslateProp) { + if (!$t[$seoTranslateProp]) { + continue; + } + $t[$seoTranslateProp] = $translateAPI->translate($t[$seoTranslateProp], $locale, $mainLocale); + } + + $data[$locale][] = $t; } } - $this->setTranslations($prop, $data); } + $this->setTranslations('seo', $data); - Api::setCache(Files::mkdir(protected_path('cache/azure_translate'))); - $translateAPI = new Api(env('AZURE_TRANSLATE_API_KEY')); $translations = $this->getTranslations('texts'); foreach ($locales as $locale) { diff --git a/app/SubForms/Webflow/Redirection.php b/app/SubForms/Webflow/Redirection.php new file mode 100644 index 000000000..798a35a85 --- /dev/null +++ b/app/SubForms/Webflow/Redirection.php @@ -0,0 +1,17 @@ +addField('from', Text::class, __('Ancienne URL')); + $this->addField('to', WebflowPage::class, __('Redirigée vers')); + } +}