You are here

function l10n_update_batch_fetch_import in Localization update 7.2

Batch process: Import translation file.

Imports a gettext file from the translation directory. When successfully the translation status is updated.

Parameters

string $project: Name of the translatable project.

string $langcode: Language code.

array $options: Array of import options.

array $context: The batch context.

See also

l10n_update_batch_import_files()

l10n_update_batch_fetch_download()

1 string reference to 'l10n_update_batch_fetch_import'
_l10n_update_fetch_operations in ./l10n_update.fetch.inc
Helper function to construct the batch operations to fetch translations.

File

./l10n_update.batch.inc, line 169
Batch process to check the availability of remote or local po files.

Code

function l10n_update_batch_fetch_import($project, $langcode, array $options, &$context) {
  $sources = l10n_update_get_status(array(
    $project,
  ), array(
    $langcode,
  ));
  if (isset($sources[$project][$langcode])) {
    $source = $sources[$project][$langcode];
    if (isset($source->type)) {
      if ($source->type == L10N_UPDATE_REMOTE || $source->type == L10N_UPDATE_LOCAL) {
        $file = $source->files[L10N_UPDATE_LOCAL];
        module_load_include('bulk.inc', 'l10n_update');
        $options += array(
          'message' => t('Importing translation for %project.', array(
            '%project' => $source->project,
          )),
        );

        // Import the translation file. For large files the batch operations is
        // progressive and will be called repeatedly until finished.
        l10n_update_batch_import($file, $options, $context);

        // The import is finished.
        if (isset($context['finished']) && $context['finished'] == 1) {

          // The import is successful.
          if (isset($context['results']['files'][$file->uri])) {
            $context['message'] = t('Imported translation for %project.', array(
              '%project' => $source->project,
            ));

            // Save the data of imported source into the {l10n_update_file}
            // table and update the current translation status.
            l10n_update_status_save($project, $langcode, L10N_UPDATE_CURRENT, $source->files[L10N_UPDATE_LOCAL]);
          }
        }
      }
    }
  }
}