You are here

function _locale_import_po in Drupal 4

Same name and namespace in other branches
  1. 5 includes/locale.inc \_locale_import_po()
  2. 6 includes/locale.inc \_locale_import_po()
  3. 7 includes/locale.inc \_locale_import_po()

Parses Gettext Portable Object file information and inserts into database

Parameters

$file Object contains properties of local file to be imported:

$lang Language code:

$mode should existing translations be replaced?:

1 call to _locale_import_po()
_locale_admin_import_submit in includes/locale.inc
Process the locale import form submission.

File

includes/locale.inc, line 448
Admin-related functions for locale.module.

Code

function _locale_import_po($file, $lang, $mode) {

  // If not in 'safe mode', increase the maximum execution time:
  if (!ini_get('safe_mode')) {
    set_time_limit(240);
  }

  // Check if we have the language already in the database
  if (!db_fetch_object(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $lang))) {
    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 = _locale_import_read_po($file, $mode, $lang);
  if ($status === FALSE) {

    // error messages are set in _locale_import_read_po
    return FALSE;
  }

  // Get status information on import process
  list($headerdone, $additions, $updates) = _locale_import_one_string('report', $mode);
  if (!$headerdone) {
    drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array(
      '%filename' => theme('placeholder', $file->filename),
    )), 'error');
  }

  // rebuild locale cache
  cache_clear_all("locale:{$lang}");

  // rebuild the menu, strings may have changed
  menu_rebuild();
  drupal_set_message(t('The translation was successfully imported. There are %number newly created translated strings and %update strings were updated.', array(
    '%number' => $additions,
    '%update' => $updates,
  )));
  watchdog('locale', t('Imported %file into %locale: %number new strings added and %update updated.', array(
    '%file' => theme('placeholder', $file->filename),
    '%locale' => theme('placeholder', $lang),
    '%number' => $additions,
    '%update' => $updates,
  )));
  return TRUE;
}