You are here

function drush_language_translations_export in Drush Language Commands 7

Export translations from one or more locale groups.

@option array $groups Comma separated list of locale groups. Defaults to 'all'. @option bool $replace Replace existing translations in the file-system. Defaults to 'false'. @option bool $sort Sorts the generated po file by source and context, defaults to 'true'. @option bool $filter Removes empty translations from the generated po file, defaults to 'true'.

Parameters

string $langcode: The langcode of the language to be exported.

string $path: Path to a directory where the translation files should be saved. Can be a file-name if one locale-group is exported.

Return value

void Save a file or prints it to StOut.

1 string reference to 'drush_language_translations_export'
language_translations_drush_command in ./language_translations.drush.inc
Implements of hook_drush_command().

File

./language_translations.drush.inc, line 277
Drush language commands related to translations.

Code

function drush_language_translations_export($langcode, $path) {

  // Check required arguments.
  if (empty($langcode) || empty($path)) {
    drush_log(dt('drush language: missing required argument'), 'error');
    return;
  }

  // Parse arguments and options.
  $path = _drush_language_translations_get_absolute_path($path);
  $language = _drush_language_translations_get_language($langcode);
  $groups = explode(',', drush_get_option('groups', 'all'));
  $groups = _drush_language_translations_groups_filter($groups);
  if (empty($path) || empty($language) || empty($groups)) {
    drush_log(dt("drush language: could not parse arguments or groups"), 'error');
    return;
  }

  // If one group is exported, it is possible to save to one file.
  // Default behavior is saving to a directory.
  if (!is_dir($path)) {
    drush_set_error(dt("drush language-export: you must supply a valid directory path." . "\n" . "drush language-export: supplied path = " . $path));
    return;
  }

  // Execution.
  foreach ($groups as $group) {
    $file_name = $group . "." . $langcode . ".po";
    $tmp_file_path = $path . DIRECTORY_SEPARATOR . $file_name;
    _drush_language_translations_export_file($tmp_file_path, $language, $group);
  }
}