You are here

function i18ntaxonomy_taxonomy in Internationalization 6

Implementation of hook_taxonomy().

$edit parameter may be an array or an object !!

File

i18ntaxonomy/i18ntaxonomy.module, line 265
i18n taxonomy module

Code

function i18ntaxonomy_taxonomy($op, $type, $edit = NULL) {
  global $language;
  $edit = (array) $edit;
  switch ("{$type}/{$op}") {
    case 'term/insert':
    case 'term/update':
      switch (i18ntaxonomy_vocabulary($edit['vid'])) {
        case I18N_TAXONOMY_LOCALIZE:

          // Update strings for localizable vocabulary.
          $tid = $edit['tid'];
          i18nstrings_update("taxonomy:term:{$tid}:name", $edit['name']);
          i18nstrings_update("taxonomy:term:{$tid}:description", $edit['description']);
          break;
        case I18N_TAXONOMY_LANGUAGE:

          // Predefined language for all terms
          if (empty($edit['language']) && ($voc = taxonomy_vocabulary_load($edit['vid']))) {
            _i18ntaxonomy_term_set_lang($edit['tid'], $voc->language);
          }
          break;
        case I18N_TAXONOMY_TRANSLATE:

          // Multilingual terms, translatable
          if (empty($edit['language'])) {
            if (!empty($edit['i18ntaxonomy_form'])) {

              // Only for the case the term has no language, it may need to be removed from translation set
              _i18ntaxonomy_term_set_lang($edit['tid'], NULL);
            }
            elseif ($lang = _i18n_get_context_lang()) {

              // The term may come from a node tags field, just if this is not a taxonomy form
              _i18ntaxonomy_term_set_lang($edit['tid'], $lang);
            }
            else {

              // Not from the taxonomy form nor node form, set current language
              _i18ntaxonomy_term_set_lang($edit['tid'], $language->language);
            }
          }
          break;
      }
      break;
    case 'vocabulary/insert':
    case 'vocabulary/update':
      $vid = $edit['vid'];

      // Update vocabulary settings.
      if (isset($edit['i18nmode'])) {
        i18ntaxonomy_vocabulary($vid, $edit['i18nmode']);
        $edit_lang = isset($edit['language']) ? $edit['language'] : '';
        db_query("UPDATE {vocabulary} SET language='%s' WHERE vid = %d", $edit_lang, $edit['vid']);
        if ($edit_lang && $op == 'update') {
          db_query("UPDATE {term_data} SET language='%s' WHERE vid = %d", $edit_lang, $edit['vid']);
          drupal_set_message(t('Reset language for all terms.'));
        }

        // Always add vocabulary translation if !$language.
        if (!$edit_lang) {
          i18nstrings_update("taxonomy:vocabulary:{$vid}:name", $edit['name']);
        }
      }
      break;
    case 'term/delete':
      $tid = $edit['tid'];
      i18nstrings_remove_string("taxonomy:term:{$tid}:name");
      i18nstrings_remove_string("taxonomy:term:{$tid}:description");
      break;
    case 'vocabulary/delete':
      $vid = $edit['vid'];
      i18nstrings_remove_string("taxonomy:vocabulary:{$vid}:name");
      break;
  }
}