use App\Jobs\WebflowPublish;
use App\Models\Base\ToolboxTranslatableModel;
use App\Services\Webflow;
+use App\SubForms\Webflow\Redirection;
use App\SubForms\Webflow\SEOPage;
use App\SubForms\Webflow\WebflowText;
use Cubist\Azure\Translate\Api;
$this->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);
}
$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) {