首页 > php教程 > PHP源码 > 正文

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

PHP中文网
发布: 2016-05-25 16:58:42
原创
1565人浏览过

项目有两种语言,taxonomy term的语言模式为translate,转换为localize。

豆绘AI
豆绘AI

豆绘AI是国内领先的AI绘图与设计平台,支持照片、设计、绘画的一键生成。

豆绘AI 485
查看详情 豆绘AI
 $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();
    }
  }
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号