I'd like to set a vocabulary's translation mode to "translate" (I18N_MODE_TRANSLATE") programmatically in my module. I've looked at the API and can't find a way to do this... I thought this would set the mode:

$taxonomy_name = 'time_category';
$taxonomy_vocab = taxonomy_vocabulary_machine_name_load($taxonomy_name);
i18n_taxonomy_vocabulary_mode($taxonomy_vocab->vid, I18N_MODE_TRANSLATE);

But it doesn't seem to work...

Comments

hillaryneaf’s picture

Issue summary: View changes
atulkamboj’s picture

Try the below code and it will set the mode to 'Translate':

$taxonomy_vocab = taxonomy_vocabulary_machine_name_load('time_category');
$taxonomy_vocab->i18n_mode = 4; //4 is "translate" option
taxonomy_vocabulary_save($taxonomy_vocab);
hillaryneaf’s picture

Status: Active » Closed (fixed)

Thanks ;)

kajalkiran’s picture

Hi,

My task was to set all the vocabularies to i18n_mode = 1. So, I was able to do this by

  // Enable localization for all of the existing vocabularies.
  // Get all the vocabularies.
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $key => $vocabulary) {
    // Load vocabulary with machine name.
    $taxonomy_vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary->machine_name);
    // Set localization value to 1.
    // Such that Terms are common for all languages.
    // but their name and description may be localized.
    $taxonomy_vocabulary->i18n_mode = 1;
    // Save vocabulary.
    taxonomy_vocabulary_save($taxonomy_vocabulary);
  }

Hope this helps !!