function drush_language_translations_import in Drush Language Commands 7
Import translations to one or more locale groups.
@todo Add language if not existing on site.
@option array $groups Comma separated list of locale groups. Defaults to 'all'. @option bool $replace Replace existing translations in the database. Defaults to 'false'.
Parameters
string $langcode: The langcode of the language to be exported.
string $path: Path to a directory with the translation files. Can be a file-name if one locale-group is imported.
Return value
void
1 string reference to 'drush_language_translations_import'
- language_translations_drush_command in ./
language_translations.drush.inc - Implements of hook_drush_command().
File
- ./
language_translations.drush.inc, line 212 - Drush language commands related to translations.
Code
function drush_language_translations_import($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 given, it is possible to read from one specific file.
if (count($groups) == 1 && reset($groups) != 'all' && is_file($path)) {
// Execute single file import.
_drush_language_translations_import_file($path, $language, reset($groups));
return;
}
elseif (!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_import_file($tmp_file_path, $language, $group);
}
}