39 lines
2.0 KiB
PHP
39 lines
2.0 KiB
PHP
<?php
|
|
// Categorías estructurales de contenido → traducciones (es_term_id => [en,fr,it,pt])
|
|
$D = [
|
|
410 => ['Nuevo Testamento', 'New Testament','Nouveau Testament','Nuovo Testamento','Novo Testamento'],
|
|
411 => ['Antiguo Testamento','Old Testament','Ancien Testament','Antico Testamento','Antigo Testamento'],
|
|
49 => ['Adviento y Navidad','Advent and Christmas','Avent et Noël','Avvento e Natale','Advento e Natal'],
|
|
12 => ['In memoriam','In Memoriam','In Memoriam','In Memoriam','In Memoriam'],
|
|
1651 => ['Noticias','News','Actualités','Notizie','Notícias'],
|
|
61 => ['Comunidades cristianas','Christian Communities','Communautés chrétiennes','Comunità cristiane','Comunidades cristãs'],
|
|
23 => ['Cartas que nos llegan','Letters We Receive','Lettres reçues','Lettere che riceviamo','Cartas que recebemos'],
|
|
39 => ['Temas','Topics','Thèmes','Temi','Temas'],
|
|
27 => ['Índice cronológico','Chronological Index','Index chronologique','Indice cronologico','Índice cronológico'],
|
|
63 => ['EFFA','EFFA','EFFA','EFFA','EFFA'],
|
|
];
|
|
$LangSlug = ['en'=>'en','fr'=>'fr','it'=>'it','pt'=>'pt'];
|
|
$created=0;
|
|
foreach ($D as $es_id => $names) {
|
|
$es_term = get_term($es_id, 'category');
|
|
if (!$es_term || is_wp_error($es_term)) { echo "skip $es_id (no existe)\n"; continue; }
|
|
$existing = pll_get_term_translations($es_id);
|
|
$group = $existing;
|
|
$i = 1;
|
|
foreach (['en','fr','it','pt'] as $L) {
|
|
$i++;
|
|
if (!empty($existing[$L])) { $group[$L]=$existing[$L]; continue; }
|
|
$name = $names[$i-1];
|
|
$slug = sanitize_title($name).'-'.$L;
|
|
$res = wp_insert_term($name, 'category', ['slug'=>$slug]);
|
|
if (is_wp_error($res)) { echo " $es_id $L ERROR: ".$res->get_error_message()."\n"; continue; }
|
|
$tid = $res['term_id'];
|
|
pll_set_term_language($tid, $L);
|
|
$group[$L] = $tid;
|
|
$created++;
|
|
}
|
|
pll_save_term_translations($group);
|
|
echo "#$es_id ".$names[0]." → ".implode(",", array_map(function($k,$v){return $k.":".$v;}, array_keys($group),$group))."\n";
|
|
}
|
|
echo "términos traducidos creados: $created\n";
|