Home >php教程 >PHP源码 >Drupal - 对某项目进行批量taxonomy term语言模式转换

Drupal - 对某项目进行批量taxonomy term语言模式转换

PHP中文网
PHP中文网Original
2016-05-25 16:58:421408browse

项目有两种语言,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();
    }
  }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:分页类12Next article:新浪新闻采集程序