You are here

function _drush_l10n_update_validate_languages in Localization update 7.2

Same name and namespace in other branches
  1. 6 l10n_update.drush.inc \_drush_l10n_update_validate_languages()
  2. 7 l10n_update.drush.inc \_drush_l10n_update_validate_languages()

Helper function to validate languages.

Used by _validate hooks. 1. Check other languages than english are available. 2. Check user provided languages are valid.

2 calls to _drush_l10n_update_validate_languages()
drush_l10n_update_status_validate in ./l10n_update.drush.inc
Validate command l10n-update-status.
drush_l10n_update_validate in ./l10n_update.drush.inc
Validate command l10n-update.

File

./l10n_update.drush.inc, line 184
Drush interface to l10n-update functionalities.

Code

function _drush_l10n_update_validate_languages() {

  // Check if there are installed languages other than english.
  $installed_languages = l10n_update_translatable_language_list();

  // Indicate that there's nothing to do, only show a warning.
  if (empty($installed_languages)) {
    drush_log(dt('No languages to update.'), 'warning');
    return FALSE;
  }

  // Check provided languages are valid.
  $languages = drush_get_option('languages', '');
  $languages = array_map('trim', _convert_csv_to_array($languages));
  if (count($languages)) {
    foreach ($languages as $key => $langcode) {
      if (!isset($installed_languages[$langcode])) {
        if (is_numeric($langcode)) {
          drush_set_error('L10N_UPDATE_INVALID_LANGUAGE', dt('Invalid language "@langcode". Use for example: --languages="nl, fr, de"', array(
            '@langcode' => $langcode,
          )));
        }
        else {
          drush_set_error('L10N_UPDATE_INVALID_LANGUAGE', dt('Language "@langcode" is not installed.', array(
            '@langcode' => $langcode,
          )));
        }
      }
      else {
        unset($languages[$key]);
        $languages[$langcode] = $installed_languages[$langcode];
      }
    }
    if (drush_get_error() != DRUSH_SUCCESS) {
      drush_print(dt('Available languages: @languages', array(
        '@languages' => implode(', ', array_keys($installed_languages)),
      )));
      return FALSE;
    }
  }
  else {
    $languages = $installed_languages;
  }
  drush_set_option('languages', $languages);
  return TRUE;
}