You are here

function l10n_update_batch_refresh in Localization update 7.2

Refreshs translations after importing strings.

Parameters

array $context: Contains a list of strings updated and information about the progress.

1 string reference to 'l10n_update_batch_refresh'
l10n_update_batch_build in ./l10n_update.bulk.inc
Build a locale batch from an array of files.

File

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

Code

function l10n_update_batch_refresh(&$context) {
  if (!isset($context['sandbox']['refresh'])) {
    $strings = $langcodes = array();
    if (isset($context['results']['stats'])) {

      // Get list of unique string identifiers and language codes updated.
      $langcodes = array_unique(array_values($context['results']['languages']));
      foreach ($context['results']['stats'] as $report) {
        $strings = array_merge($strings, $report['strings']);
      }
    }
    if ($strings) {

      // Initialize multi-step string refresh.
      $context['message'] = t('Updating translations for JavaScript and configuration strings.');
      $context['sandbox']['refresh']['strings'] = array_unique($strings);
      $context['sandbox']['refresh']['languages'] = $langcodes;
      $context['sandbox']['refresh']['names'] = array();
      $context['results']['stats']['config'] = 0;
      $context['sandbox']['refresh']['count'] = count($strings);

      // We will update strings on later steps.
      $context['finished'] = 1 - 1 / $context['sandbox']['refresh']['count'];
    }
    else {
      $context['finished'] = 1;
    }
  }
  elseif (!empty($context['sandbox']['refresh']['strings'])) {

    // Not perfect but will give some indication of progress.
    $context['finished'] = 1 - count($context['sandbox']['refresh']['strings']) / $context['sandbox']['refresh']['count'];

    // Pending strings, refresh 100 at a time, get next pack.
    $next = array_slice($context['sandbox']['refresh']['strings'], 0, 100);
    array_splice($context['sandbox']['refresh']['strings'], 0, count($next));

    // Clear cache and force refresh of JavaScript translations.
    _l10n_update_refresh_translations($context['sandbox']['refresh']['languages'], $next);
  }
  else {
    $context['finished'] = 1;
  }
}