You are here

function drush_language_add in Drush Language Commands 7

Add a language.

File

./language.drush.inc, line 69
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_add() {
  if (!function_exists('locale_add_language')) {
    drush_set_error(dt('Could not add language. Is the \'locale\' module enabled?'));
    return;
  }
  $args = func_get_args();
  if (count($args) == 0) {
    drush_set_error(dt('Please provide one or more language codes as arguments.'));
    return;
  }
  foreach ($args as $langcode) {
    if (array_key_exists($langcode, language_list())) {
      drush_log(dt('The language with code !code already exists.', array(
        '!code' => $langcode,
      )), 'warning');
    }
    else {

      // Predefined language selection.
      include_once DRUPAL_ROOT . '/includes/iso.inc';
      $predefined = _locale_get_predefined_list();
      if (!isset($predefined[$langcode])) {
        drush_log(dt('Invalid language code !language', array(
          '!language' => $langcode,
        )), 'warning');
      }
      else {

        // Add the language definition
        locale_add_language($langcode);

        // See if we have language files to import for the newly added
        // language, collect and import them.
        if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) {
          batch_set($batch);
          $batch =& batch_get();
          $batch['progressive'] = FALSE;

          // Process the batch.
          drush_backend_batch_process();
        }
        drush_log(dt('Added language: !language', array(
          '!language' => $langcode,
        )), 'ok');
      }
    }
  }
}