You are here

function drush_stringoverrides_list in String Overrides 7

Drush Callback; Lists all the String Overrides.

File

./stringoverrides.drush.inc, line 92
Drush interface for String Overrides.

Code

function drush_stringoverrides_list() {

  // Load the administration interface for API dependencies.
  module_load_include('inc', 'stringoverrides', 'stringoverrides.admin');
  $strings = array();
  $language = drush_get_option('language', 'en');

  // Retrieve the string overrides from the variables table.
  $words = array(
    FALSE => variable_get("locale_custom_disabled_strings_{$language}", array()),
    TRUE => variable_get("locale_custom_strings_{$language}", array()),
  );
  foreach ($words as $enabled => $custom_strings) {
    foreach ($custom_strings as $context => $translations) {
      foreach ($translations as $source => $translation) {
        $strings[] = array(
          'enabled' => $enabled,
          'context' => $context,
          'source' => $source,
          'translation' => $translation,
        );
      }
    }
  }

  // Only display the table if there are string overrides.
  if (empty($strings)) {
    drush_print(dt('There are currently no string overrides associated with the given language.'));
  }
  else {

    // Sort the strings before displaying them.
    usort($strings, 'stringoverrides_admin_word_sort');

    // Construct and display the table.
    $rows[] = array(
      dt(''),
      dt('Original'),
      dt('Replacement'),
      dt('Context'),
    );
    foreach ($strings as $string) {
      $rows[] = array(
        $string['enabled'] ? dt('[X]') : dt('[ ]'),
        $string['source'],
        $string['translation'],
        $string['context'],
      );
    }

    // Display in a table.
    drush_print_table($rows, TRUE);
  }
}