You are here

function drush_language_prefix in Drush Language Commands 7

Alter the language prefix.

File

./language.drush.inc, line 207
Drush commands allowing languages to be added, switched, enabled, disabled, imported, exported and update prefix from the commandline. This module only provides drush commands, so you will see no functionality in the UI.

Code

function drush_language_prefix() {
  $args = func_get_args();
  if (count($args) == 0) {
    drush_set_error(dt('Please provide one langcode as arguments. Prefix is optional, if not provide the command will remove the prefix'));
    return;
  }

  // Get arguments
  $langcode = array_shift($args);
  $prefix = array_shift($args);
  if (module_exists('locale')) {

    // Add some security filters
    if (!empty($langcode)) {
      $langcode = check_plain($langcode);
      $langcode = filter_xss($langcode);
    }
    if (!empty($prefix)) {
      $prefix = check_plain($prefix);
      $prefix = filter_xss($prefix);
    }

    // Alter prefix if language exist
    if (array_key_exists($langcode, language_list())) {
      db_update('languages')
        ->condition('language', $langcode)
        ->fields(array(
        'prefix' => $prefix,
      ))
        ->execute();
      if (!empty($prefix)) {
        drush_log(dt("Prefix !prefix set for !language", array(
          '!prefix' => $prefix,
          '!language' => $langcode,
        )), 'ok');
      }
      else {
        drush_log(dt("Prefix has been removed for !language", array(
          '!prefix' => $prefix,
          '!language' => $langcode,
        )), 'ok');
      }
    }
    else {
      drush_log(dt("Specified language does not exist !language", array(
        '!language' => $langcode,
      )), 'warning');
    }
  }
  else {
    drush_log(dt('Locale module is required', 'warning'));
  }
}