You are here

function _l10n_update_locale_import_po in Localization update 7

Same name and namespace in other branches
  1. 6 l10n_update.locale.inc \_l10n_update_locale_import_po()

Parses Gettext Portable Object file information and inserts into database

This is an improved version of _locale_import_po() to handle translation status

Parameters

$file: Drupal file object corresponding to the PO file to import

$langcode: Language code

$mode: Should existing translations be replaced LOCALE_IMPORT_KEEP or LOCALE_IMPORT_OVERWRITE

$group: Text group to import PO file into (eg. 'default' for interface translations)

Return value

boolean Result array on success. FALSE on failure

1 call to _l10n_update_locale_import_po()
l10n_update_import_file in ./l10n_update.inc
Import local file into the database.

File

./l10n_update.locale.inc, line 25
Override part of locale.inc library so we can manage string status

Code

function _l10n_update_locale_import_po($file, $langcode, $mode, $group = NULL) {

  // Try to allocate enough time to parse and import the data.
  drupal_set_time_limit(240);

  // Check if we have the language already in the database.
  if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(
    ':language' => $langcode,
  ))
    ->fetchField()) {
    drupal_set_message(t('The language selected for import is not supported.'), 'error');
    return FALSE;
  }

  // Get strings from file (returns on failure after a partial import, or on success)
  $status = _l10n_update_locale_import_read_po('db-store', $file, $mode, $langcode, $group);
  if ($status === FALSE) {

    // Error messages are set in _locale_import_read_po().
    return FALSE;
  }

  // Get status information on import process.
  list($header_done, $additions, $updates, $deletes, $skips) = _l10n_update_locale_import_one_string('db-report');
  if (!$header_done) {
    drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array(
      '%filename' => $file->filename,
    )), 'error');
  }
  watchdog('locale', 'Imported %file into %locale: %number new strings added, %update updated and %delete removed.', array(
    '%file' => $file->filename,
    '%locale' => $langcode,
    '%number' => $additions,
    '%update' => $updates,
    '%delete' => $deletes,
  ));
  if ($skips) {
    watchdog('locale', '@count disallowed HTML string(s) in %file', array(
      '@count' => $skips,
      '%file' => $file->uri,
    ), WATCHDOG_WARNING);
  }

  // Return results of this import.
  return array(
    'file' => $file,
    'language' => $langcode,
    'add' => $additions,
    'update' => $updates,
    'delete' => $deletes,
    'skip' => $skips,
  );
}