You are here

function lingotek_admin_prepare_menus in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.3 lingotek.admin.inc \lingotek_admin_prepare_menus()
  2. 7.4 lingotek.admin.inc \lingotek_admin_prepare_menus()
  3. 7.5 lingotek.admin.inc \lingotek_admin_prepare_menus()
  4. 7.6 lingotek.admin.inc \lingotek_admin_prepare_menus()
2 calls to lingotek_admin_prepare_menus()
drush_lingotek_prepare_menus in ./lingotek.drush.inc
Callback function for drush command lt-prepare-menus
lingotek_admin_additional_translation_settings_form_submit in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 1241

Code

function lingotek_admin_prepare_menus() {

  // update all menus to use 'Translate and Localize' in the Multilingual Options
  $result = db_update('menu_custom')
    ->fields(array(
    'i18n_mode' => LINGOTEK_MENU_LOCALIZE_TRANSLATE_VALUE,
  ))
    ->execute();
  menu_cache_clear_all();
  if ($result) {
    drupal_set_message(format_plural($result, t('Set 1 menu to <i>Translate and Localize</i>.'), t('Set @num menus to <i>Translate and Localize</i>.', array(
      '@num' => (int) $result,
    ))));
  }
  else {
    drupal_set_message(t('All menus already set to <i>Translate and Localize</i>.'));
  }

  // find all menu links that are not language-neutral and not part of a
  // translation set and update them to be language-neutral (so they will
  // be added to the locales_source table as a string to be translated),
  // only if advanced handling of menu items is off
  if (!variable_get('lingotek_advanced_menu_links', FALSE)) {
    $result = db_update('menu_links')
      ->fields(array(
      'language' => LANGUAGE_NONE,
    ))
      ->condition('language', LANGUAGE_NONE, '!=')
      ->condition('i18n_tsid', 0)
      ->execute();
    if ($result) {
      drupal_set_message(format_plural($result, t('Set 1 menu link to <i>language neutral</i>.'), t('Set @num menu links to <i>Language neutral</i>.', array(
        '@num' => (int) $result,
      ))));
    }
    else {
      drupal_set_message(t('All menu links already set to <i>language neutral</i>.'));
    }
  }

  // make sure all menu links have the "alter" attribute, so that
  // the i18n_menu module will check for translations
  $result = db_select('menu_links', 'ml')
    ->fields('ml', array(
    'mlid',
  ))
    ->condition('ml.options', '%alter%', 'NOT LIKE')
    ->execute()
    ->fetchCol();
  $total_links_modified = 0;
  if (!empty($result)) {
    foreach ($result as $mlid) {
      $mlink = menu_link_load($mlid);
      $mlink['options']['alter'] = TRUE;
      menu_link_save($mlink);
      $total_links_modified++;
    }
  }
  if ($total_links_modified) {
    drupal_set_message(format_plural($total_links_modified, t('Prepared one menu link for multilingual display.'), t('Prepared @num menu links for multilingual display.', array(
      '@num' => $total_links_modified,
    ))));
  }
  else {
    drupal_set_message(t('All menu links ready to display translations.'));
  }
  return TRUE;
}