You are here

function _drush_language_translations_import_file in Drush Language Commands 7

Import function for language files.

@option bool $replace Replace existing translations in the file-system. Defaults to 'false'.

Parameters

string $file_path: Absolute file path.

string $language: Language code.

string $group: Text group to export (field, default).

Return value

void Imports .po file to database.

1 call to _drush_language_translations_import_file()
drush_language_translations_import in ./language_translations.drush.inc
Import translations to one or more locale groups.

File

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

Code

function _drush_language_translations_import_file($file_path = '-', $language, $group) {

  // Parse $replace option.
  drush_get_option('replace') ? $mode = LOCALE_IMPORT_OVERWRITE : ($mode = LOCALE_IMPORT_KEEP);

  // Ensure we have the file intended for upload
  if (file_exists($file_path)) {

    // Construct fake file object
    $file = new stdClass();
    $file->uid = 1;
    $file->status = 0;
    $file->filename = trim(drupal_basename($file_path), '.');
    $file->uri = $file_path;

    // Now import strings into the language
    if ($return = _locale_import_po($file, $language->language, $mode, $group) == FALSE) {
      $variables = array(
        '%filename' => $file->filename,
      );
      drush_log(dt('The translation import of %filename failed.', $variables), 'error');
      watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
    }
    else {
      drush_log(dt('drush language-import: ' . $file_path), 'success');
    }
  }
  else {
    $variables = array(
      '!filepath' => $file_path,
    );
    drush_log(dt('File to import at !filepath not found.', $variables), 'error');
  }
}