作者:台球吴蒙蒙向_521 | 来源:互联网 | 2018-03-22 15:20
项目有两种语言,taxonomy term的语言模式为Translate,转换为Localize。
$debug = true;
$machine_name = 'clinical_centres';
$root = taxonomy_vocabulary_machine_name_load($machine_name);
$root->i18n_mode =1;
taxonomy_vocabulary_save($root);
$tree = i18n_taxonomy_get_tree($root->vid,'en');
dsm($tree);
$tree_new = array();
foreach($tree as $index=>$term){
$term_und = i18n_taxonomy_term_get_translation($term,'und');
$term_new = $term_und?$term_und:new stdClass();
$term_new->name = $term->name;
$term_new->description = $term->description;
$term_new->format = 'full_html';
$term_new->vocabulary_machine_name = $machine_name;
$term_new->language = 'und';
$term_new->vid = $root->vid;//$root_new->vid;
$term_new->parent[0] = 0;
$term_new->weight = $term->weight;
if($term->parents[0]>0){
foreach($tree as $tmp_index=>$tmp){
if(in_array($tmp->tid, $term->parents)){
$term_new->parent[0] = $tree_new[$tmp_index]->tid;
break;
}
}
}
taxonomy_term_save($term_new);
$tree_new[$index] = $term_new;
$translation_set = i18n_translation_set_load($term->i18n_tsid);
if($translation_set){
$term_zh = $translation_set->get_item('zh-hant');
$term_en = $translation_set->get_item('en');
//译文
i18n_string_textgroup('taxonomy')->update_translation(array('term', $term_new->tid, 'name'), 'zh-hant', $term_zh->name);
i18n_taxonomy_taxonomy_term_delete($term_zh);
taxonomy_term_delete($term_zh->tid);
i18n_taxonomy_taxonomy_term_delete($term_en);
taxonomy_term_delete($term_en->tid);
$translation_set->get_translations();
$translation_set->remove_language('zh-hant');
$translation_set->remove_language('en');
$translation_set->update_delete();
}
}