You are here

function l10n_update_batch_import_files in Localization update 7.2

Prepare a batch to import all translations.

@todo Integrate with update status to identify projects needed and integrate l10n_update functionality to feed in translation files alike. See https://www.drupal.org/node/1191488.

Parameters

array $options: An array with options that can have the following elements:

  • 'langcode': The language code. Optional, defaults to NULL, which means that the language will be detected from the name of the files.
  • 'overwrite_options': Overwrite options array as defined in PoDatabaseWriter. Optional, defaults to an empty array.
  • 'customized': Flag indicating whether the strings imported from $file are customized translations or come from a community source. Use L10N_UPDATE_CUSTOMIZED or L10N_UPDATE_NOT_CUSTOMIZED. Optional, defaults to L10N_UPDATE_NOT_CUSTOMIZED.
  • 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Optional, defaults to TRUE.

bool $force: (optional) Import all available files, even if they were imported before.

File

./l10n_update.bulk.inc, line 292
Mass import-export and batch import functionality for Gettext .po files.

Code

function l10n_update_batch_import_files(array $options, $force = FALSE) {
  $options += array(
    'overwrite_options' => array(),
    'customized' => L10N_UPDATE_NOT_CUSTOMIZED,
    'finish_feedback' => TRUE,
  );
  if (!empty($options['langcode'])) {
    $langcodes = array(
      $options['langcode'],
    );
  }
  else {

    // If langcode was not provided, make sure to only import files for the
    // languages we have enabled.
    $langcodes = array_keys(language_list());
  }
  $files = l10n_update_get_interface_translation_files(array(), $langcodes);
  if (!$force) {
    $result = db_select('l10n_update_file', 'lf')
      ->fields('lf', array(
      'langcode',
      'uri',
      'timestamp',
    ))
      ->condition('language', $langcodes)
      ->execute()
      ->fetchAllAssoc('uri');
    foreach ($result as $uri => $info) {
      if (isset($files[$uri]) && filemtime($uri) <= $info->timestamp) {

        // The file is already imported and not changed since the last import.
        // Remove it from file list and don't import it again.
        unset($files[$uri]);
      }
    }
  }
  return l10n_update_batch_build($files, $options);
}