locale.pages.inc 23.5 KB
Newer Older
1 2 3
<?php

/**
4 5
 * @file
 * Interface translation summary, editing and deletion user interfaces.
6 7
 */

8 9
use Drupal\locale\SourceString;
use Drupal\locale\TranslationString;
10 11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

12
/**
13 14 15
 * Page callback: Shows the string search screen.
 *
 * @see locale_menu()
16
 */
17 18 19 20 21
function locale_translate_page() {
  return array(
    'filter' => drupal_get_form('locale_translate_filter_form'),
    'form' => drupal_get_form('locale_translate_edit_form'),
  );
22 23 24
}

/**
25 26 27 28
 * Builds a string search query and returns an array of string objects.
 *
 * @return array
 *   Array of Drupal\locale\TranslationString objects.
29
 */
30
function locale_translate_filter_load_strings() {
31
  $filter_values = locale_translate_filter_values();
32

33 34
  // Language is sanitized to be one of the possible options in
  // locale_translate_filter_values().
35 36
  $conditions = array('language' => $filter_values['langcode']);
  $options = array('pager limit' => 30, 'translated' => TRUE, 'untranslated' => TRUE);
37

38
  // Add translation status conditions and options.
39
  switch ($filter_values['translation']) {
40
    case 'translated':
41
      $conditions['translated'] = TRUE;
42
      if ($filter_values['customized'] != 'all') {
43
        $conditions['customized'] = $filter_values['customized'];
44
      }
45
      break;
46

47
    case 'untranslated':
48
      $conditions['translated'] = FALSE;
49 50 51 52
      break;

  }

53 54 55 56 57 58 59 60
  if (!empty($filter_values['string'])) {
    $options['filters']['source'] = $filter_values['string'];
    if ($options['translated']) {
      $options['filters']['translation'] = $filter_values['string'];
    }
  }

  return locale_storage()->getTranslations($conditions, $options);
61 62 63
}

/**
64
 * Build array out of search criteria specified in request variables.
65
 */
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
function locale_translate_filter_values() {
  $filter_values = &drupal_static(__FUNCTION__);
  if (!isset($filter_values)) {
    $filter_values = array();
    $filters = locale_translate_filters();
    foreach ($filters as $key => $filter) {
      $filter_values[$key] = $filter['default'];
      // Let the filter defaults be overwritten by parameters in the URL.
      if (isset($_GET[$key])) {
        // Only allow this value if it was among the options, or
        // if there were no fixed options to filter for.
        if (!isset($filter['options']) || isset($filter['options'][$_GET[$key]])) {
          $filter_values[$key] = $_GET[$key];
        }
      }
      elseif (isset($_SESSION['locale_translate_filter'][$key])) {
        // Only allow this value if it was among the options, or
        // if there were no fixed options to filter for.
        if (!isset($filter['options']) || isset($filter['options'][$_SESSION['locale_translate_filter'][$key]])) {
          $filter_values[$key] = $_SESSION['locale_translate_filter'][$key];
        }
87 88 89
      }
    }
  }
90
  return $filter_values;
91 92 93 94 95
}

/**
 * List locale translation filters that can be applied.
 */
96
function locale_translate_filters() {
97 98
  $filters = array();

99
  // Get all languages, except English.
100
  drupal_static_reset('language_list');
101
  $languages = language_list();
102 103 104 105 106
  $language_options = array();
  foreach ($languages as $langcode => $language) {
    if ($langcode != 'en' || locale_translate_english()) {
      $language_options[$langcode] = $language->name;
    }
107
  }
108

109
  // Pick the current interface language code for the filter.
110
  $default_langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode;
111 112 113 114 115
  if (!isset($language_options[$default_langcode])) {
    $available_langcodes = array_keys($language_options);
    $default_langcode = array_shift($available_langcodes);
  }

116 117 118
  $filters['string'] = array(
    'title' => t('String contains'),
    'description' => t('Leave blank to show all strings. The search is case sensitive.'),
119
    'default' => '',
120 121
  );

122 123 124 125
  $filters['langcode'] = array(
    'title' => t('Translation language'),
    'options' => $language_options,
    'default' => $default_langcode,
126 127 128 129
  );

  $filters['translation'] = array(
    'title' => t('Search in'),
130 131 132
    'options' => array(
      'all' => t('Both translated and untranslated strings'),
      'translated' => t('Only translated strings'),
133
      'untranslated' => t('Only untranslated strings'),
134
    ),
135
    'default' => 'all',
136 137 138 139 140 141 142 143 144 145 146 147
  );

  $filters['customized'] = array(
    'title' => t('Translation type'),
    'options' => array(
      'all' => t('All'),
      LOCALE_NOT_CUSTOMIZED => t('Non-customized translation'),
      LOCALE_CUSTOMIZED => t('Customized translation'),
    ),
    'states' => array(
      'visible' => array(
        ':input[name=translation]' => array('value' => 'translated'),
148
      ),
149
    ),
150
    'default' => 'all',
151 152 153 154 155 156 157 158 159 160
  );

  return $filters;
}

/**
 * Return form for locale translation filters.
 *
 * @ingroup forms
 */
161 162 163 164 165 166 167
function locale_translate_filter_form($form, &$form_state) {
  $filters = locale_translate_filters();
  $filter_values = locale_translate_filter_values();

  $form['#attached']['css'] = array(
    drupal_get_path('module', 'locale') . '/locale.admin.css',
  );
168 169

  $form['filters'] = array(
170
    '#type' => 'details',
171 172 173 174 175 176 177 178
    '#title' => t('Filter translatable strings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  foreach ($filters as $key => $filter) {
    // Special case for 'string' filter.
    if ($key == 'string') {
      $form['filters']['status']['string'] = array(
179
        '#type' => 'search',
180 181
        '#title' => $filter['title'],
        '#description' => $filter['description'],
182
        '#default_value' => $filter_values[$key],
183 184 185
      );
    }
    else {
186
      $empty_option = isset($filter['options'][$filter['default']]) ? $filter['options'][$filter['default']] : '<none>';
187 188 189
      $form['filters']['status'][$key] = array(
        '#title' => $filter['title'],
        '#type' => 'select',
190 191
        '#empty_value' => $filter['default'],
        '#empty_option' => $empty_option,
192 193
        '#size' => 0,
        '#options' => $filter['options'],
194
        '#default_value' => $filter_values[$key],
195
      );
196 197 198
      if (isset($filter['states'])) {
        $form['filters']['status'][$key]['#states'] = $filter['states'];
      }
199 200 201 202 203 204 205 206 207 208 209
    }
  }

  $form['filters']['actions'] = array(
    '#type' => 'actions',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['filters']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
  );
210
  if (!empty($_SESSION['locale_translate_filter'])) {
211 212
    $form['filters']['actions']['reset'] = array(
      '#type' => 'submit',
213
      '#value' => t('Reset'),
214 215 216 217 218 219 220 221 222
    );
  }

  return $form;
}

/**
 * Process result from locale translation filter form.
 */
223
function locale_translate_filter_form_submit($form, &$form_state) {
224
  $op = $form_state['values']['op'];
225
  $filters = locale_translate_filters();
226 227 228 229
  switch ($op) {
    case t('Filter'):
      foreach ($filters as $name => $filter) {
        if (isset($form_state['values'][$name])) {
230
          $_SESSION['locale_translate_filter'][$name] = $form_state['values'][$name];
231 232 233
        }
      }
      break;
234

235
    case t('Reset'):
236
      $_SESSION['locale_translate_filter'] = array();
237
      break;
238

239 240 241 242 243 244
  }

  $form_state['redirect'] = 'admin/config/regional/translate/translate';
}

/**
245 246 247 248 249
 * Form constructor for the string editing form.
 *
 * @see locale_menu()
 * @see locale_translate_edit_form_validate()
 * @see locale_translate_edit_form_submit()
250 251
 *
 * @ingroup forms
252
 */
253 254 255 256 257 258 259 260 261 262 263 264
function locale_translate_edit_form($form, &$form_state) {
  $filter_values = locale_translate_filter_values();
  $langcode = $filter_values['langcode'];

  drupal_static_reset('language_list');
  $languages = language_list();

  $langname = isset($langcode) ? $languages[$langcode]->name : "<none>";

  $path = drupal_get_path('module', 'locale');
  $form['#attached']['css'] = array(
    $path . '/locale.admin.css',
265
  );
266
  $form['#attached']['library'][] = array('locale', 'drupal.locale.admin');
267

268 269 270 271
  $form['langcode'] = array(
    '#type' => 'value',
    '#value' => $filter_values['langcode'],
  );
272

273 274 275 276 277
  $form['strings'] = array(
    '#type' => 'item',
    '#tree' => TRUE,
    '#language' => $langname,
    '#theme' => 'locale_translate_edit_form_strings',
278 279
  );

280
  if (isset($langcode)) {
281
    $strings = locale_translate_filter_load_strings();
282 283 284 285

    $plural_formulas = variable_get('locale_translation_plurals', array());

    foreach ($strings as $string) {
286 287
      // Cast into source string, will do for our purposes.
      $source = new SourceString($string);
288
      // Split source to work with plural values.
289 290
      $source_array = $source->getPlurals();
      $translation_array = $string->getPlurals();
291 292 293 294 295 296 297 298 299 300 301 302
      if (count($source_array) == 1) {
        // Add original string value and mark as non-plural.
        $form['strings'][$string->lid]['plural'] = array(
          '#type' => 'value',
          '#value' => 0,
        );
        $form['strings'][$string->lid]['original'] = array(
          '#type' => 'item',
          '#title' => t('Source string'),
          '#title_display' => 'invisible',
          '#markup' => check_plain($source_array[0]),
        );
303 304
      }
      else {
305 306 307 308 309 310 311
        // Add original string value and mark as plural.
        $form['strings'][$string->lid]['plural'] = array(
          '#type' => 'value',
          '#value' => 1,
        );
        $form['strings'][$string->lid]['original_singular'] = array(
          '#type' => 'item',
312
          '#title' => t('Singular form'),
313
          '#markup' => check_plain($source_array[0]),
314
        );
315 316
        $form['strings'][$string->lid]['original_plural'] = array(
          '#type' => 'item',
317
          '#title' => t('Plural form'),
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
          '#markup' => check_plain($source_array[1]),
        );
      }
      if (!empty($string->context)) {
        $form['strings'][$string->lid]['context'] = array(
          '#type' => 'value',
          '#value' => check_plain($string->context),
        );
      }
      // Approximate the number of rows to use in the default textarea.
      $rows = min(ceil(str_word_count($source_array[0]) / 12), 10);
      if (empty($form['strings'][$string->lid]['plural']['#value'])) {
        $form['strings'][$string->lid]['translations'][0] = array(
          '#type' => 'textarea',
          '#title' => t('Translated string'),
          '#title_display' => 'invisible',
334
          '#rows' => $rows,
335
          '#default_value' => $translation_array[0],
336 337
        );
      }
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
      else {
        // Dealing with plural strings.
        if (isset($plural_formulas[$langcode]['plurals']) && $plural_formulas[$langcode]['plurals'] > 2) {
          // Add a textarea for each plural variant.
          for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) {
            $form['strings'][$string->lid]['translations'][$i] = array(
              '#type' => 'textarea',
              '#title' => ($i == 0 ? t('Singular form') : format_plural($i, 'First plural form', '@count. plural form')),
              '#rows' => $rows,
              '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '',
            );
          }
        }
        else {
          // Fallback for unknown number of plurals.
          $form['strings'][$string->lid]['translations'][0] = array(
            '#type' => 'textarea',
            '#title' => t('Singular form'),
            '#rows' => $rows,
            '#default_value' => $translation_array[0],
          );
          $form['strings'][$string->lid]['translations'][1] = array(
            '#type' => 'textarea',
            '#title' => t('Plural form'),
            '#rows' => $rows,
            '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '',
          );
        }
      }
367
    }
368 369 370
    if (count(element_children($form['strings']))) {
      $form['actions'] = array('#type' => 'actions');
      $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save translations'));
371
    }
372 373 374 375 376
  }
  return $form;
}

/**
377 378 379
 * Form validation handler for locale_translate_edit_form().
 *
 * @see locale_translate_edit_form_submit()
380 381
 */
function locale_translate_edit_form_validate($form, &$form_state) {
382 383 384
  $langcode = $form_state['values']['langcode'];
  foreach ($form_state['values']['strings'] as $lid => $translations) {
    foreach ($translations['translations'] as $key => $value) {
385
      if (!locale_string_is_safe($value)) {
386
        form_set_error("strings][$lid][translations][$key", t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
387 388 389
        form_set_error("translations][$langcode][$key", t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
        watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);
      }
390 391 392 393 394
    }
  }
}

/**
395 396 397
 * Form submission handler for locale_translate_edit_form().
 *
 * @see locale_translate_edit_form_validate()
398 399
 */
function locale_translate_edit_form_submit($form, &$form_state) {
400
  $langcode = $form_state['values']['langcode'];
401 402 403 404 405 406 407 408
  $updated = array();

  // Preload all translations for strings in the form.
  $lids = array_keys($form_state['values']['strings']);
  $strings = array();
  foreach (locale_storage()->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $string) {
    $strings[$string->lid] = $string;
  }
409

410
  foreach ($form_state['values']['strings'] as $lid => $translations) {
411 412
    // No translation when all strings are empty.
    $has_translation = FALSE;
413
    foreach ($translations['translations'] as $string) {
414 415 416 417 418 419
      if (!empty($string)) {
        $has_translation = TRUE;
        break;
      }
    }
    if ($has_translation) {
420
      // Only update or insert if we have a value to use.
421
      $target = isset($strings[$lid]) ? $strings[$lid] : locale_storage()->createTranslation(array('lid' => $lid, 'language' => $langcode));
422 423 424
      $target->setPlurals($translations['translations'])
        ->setCustomized()
        ->save();
425
      $updated[] = $target->getId();
426
    }
427
    elseif (isset($strings[$lid])) {
428
      // Empty translation entered: remove existing entry from database.
429 430
      $strings[$lid]->delete();
      $updated[] = $lid;
431 432 433
    }
  }

434 435 436 437 438 439
  drupal_set_message(t('The strings have been saved.'));

  // Keep the user on the current pager page.
  if (isset($_GET['page'])) {
    $form_state['redirect'] = array('admin/config/regional/translate', array('query' => array('page' => $_GET['page'])));
  }
440

441 442 443 444 445
  if ($updated) {
    // Clear cache and force refresh of JavaScript translations.
    _locale_refresh_translations(array($langcode), $updated);
  }

446 447 448
}

/**
449 450 451 452 453 454 455 456 457
 * Page callback: Checks for translation updates and displays the translations status.
 *
 * Manually checks the translation status without the use of cron.
 *
 * @see locale_menu()
 */
function locale_translation_manual_status() {
  module_load_include('compare.inc', 'locale');

458 459 460
  // Check translation status of all translatable project in all languages.
  // First we clear the cached list of projects. Although not strictly
  // nescessary, this is helpfull in case the project list is out of sync.
461
  locale_translation_flush_projects();
462
  locale_translation_check_projects();
463

464 465
  // Execute a batch if required. A batch is only used when remote files
  // are checked.
466 467 468 469 470 471
  if (batch_get()) {
    batch_process('admin/reports/translations');
  }
  drupal_goto('admin/reports/translations');
}

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
/**
 * Page callback: Configuration for interface translation.
 *
 * @see locale_menu()
 */
function locale_translate_settings($form, &$form_state) {
  $config = config('locale.settings');

  $form['update_interval_days'] = array(
    '#type' => 'radios',
    '#title' => t('Check for updates'),
    '#default_value' => $config->get('translation.update_interval_days'),
    '#options' => array(
      '0' => t('Never (manually)'),
      '1' => t('Daily'),
      '7' => t('Weekly'),
    ),
    '#description' => t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href="@url">Check updates now</a>.', array('@url' => url('admin/reports/translations/check'))),
  );

  $form['check_disabled_modules'] = array(
    '#type' => 'checkbox',
    '#title' => t('Check for updates of disabled modules and themes'),
    '#default_value' => $config->get('translation.check_disabled_modules'),
  );

  if ($directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations')) {
    $description = t('Translation files are stored locally in the  %path directory. You can change this directory on the <a href="@url">File system</a> configuration page.', array('%path' => $directory, '@url' => url('admin/config/media/file-system')));
  }
  else {
    $description = t('Translation files will not be stored locally. Change the Interface translation directory on the <a href="@url">File system configuration</a> page.', array('@url' => url('admin/config/media/file-system')));
  }
  $form['#translation_directory'] = $directory;
  $form['use_source'] = array(
    '#type' => 'radios',
    '#title' => t('Translation source'),
    '#default_value' => $config->get('translation.use_source'),
    '#options' => array(
      LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL => t('Drupal translation server and local files'),
      LOCALE_TRANSLATION_USE_SOURCE_LOCAL => t('Local files only'),
    ),
    '#description' => t('The source of translation files for automatic interface translation.') . ' ' . $description,
  );

  if ($config->get('translation.overwrite_not_customized') == FALSE) {
    $default = LOCALE_TRANSLATION_OVERWRITE_NONE;
  }
  elseif ($config->get('translation.overwrite_customized') == TRUE) {
    $default = LOCALE_TRANSLATION_OVERWRITE_ALL;
  }
  else {
    $default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED;
  }
  $form['overwrite'] = array(
    '#type' => 'radios',
    '#title' => t('Import behaviour'),
    '#default_value' => $default,
    '#options' => array(
      LOCALE_TRANSLATION_OVERWRITE_NONE => t("Don't overwrite existing translations."),
      LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED => t('Only overwrite imported translations, customized translations are kept.'),
      LOCALE_TRANSLATION_OVERWRITE_ALL => t('Overwrite existing translations.'),
    ),
    '#description' => t('How to treat existing translations when automatically updating the interface translations.'),
  );

  return system_config_form($form, $form_state);
}

/**
 * Form validation handler for locale_translate_settings().
 *
 * @see locale_translate_settings()
 */
function locale_translate_settings_validate($form, &$form_state) {
  if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
    form_set_error('use_source', t('You have selected local translation source, but no <a href="@url">Interface translation directory</a> was configured.', array('@url' => url('admin/config/media/file-system'))));
  }
}

/**
 * Form submission handler for locale_translate_settings().
 *
 * @see locale_translate_settings()
 */
function locale_translate_settings_submit($form, &$form_state) {
  $values = $form_state['values'];

  $config = config('locale.settings');
  $config->set('translation.update_interval_days', $values['update_interval_days'])->save();
  $config->set('translation.use_source', $values['use_source'])->save();

  switch ($values['overwrite']) {
    case LOCALE_TRANSLATION_OVERWRITE_ALL:
      $config
        ->set('translation.overwrite_customized', TRUE)
        ->set('translation.overwrite_not_customized', TRUE);
      break;
    case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED:
      $config
        ->set('translation.overwrite_customized', FALSE)
        ->set('translation.overwrite_not_customized', TRUE);
      break;
    case LOCALE_TRANSLATION_OVERWRITE_NONE:
      $config
        ->set('translation.overwrite_customized', FALSE)
        ->set('translation.overwrite_not_customized', FALSE);
      break;
  }

  $config
    ->set('translation.check_disabled_modules', $values['check_disabled_modules'])
    ->save();

  // Invalidate the cached translation status when the configuration setting of
  // 'use_source' and 'check_disabled_modules' change.
  if ($form['use_source']['#default_value'] != $form_state['values']['use_source'] ||
      $form['check_disabled_modules']['#default_value'] != $form_state['values']['check_disabled_modules']) {
    locale_translation_clear_status();
  }
}

593 594 595 596 597
/**
 * Page callback: Display the current translation status.
 *
 * @see locale_menu()
 */
598 599 600
function locale_translation_status_form($form, &$form_state) {
  module_load_include('compare.inc', 'locale');

601
  $languages = locale_translatable_language_list();
602 603
  $status = state()->get('locale.translation_status');

604 605 606 607
  if (!$languages) {
    drupal_set_message(t('No translatable languages available. <a href="@add_lanuage">Add language</a> first.', array('@add_lanuage' => url('admin/config/regional/language'))), 'warning');
  }

608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  $last = state()->get('locale.translation_last_checked');
  $markup = '<div class="locale checked">';
  $markup .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never');
  $markup .= ' <span class="check-manually">(' . l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination())) . ')</span>';
  $markup .= "</div>\n";
  $form['last_checked'] = array(
    '#markup' => '<p>' . $markup . '</p>',
  );

  $form['langcodes'] = array(
    '#type' => 'value',
    '#value' => drupal_map_assoc(array_keys($languages)),
  );

  $form['actions'] = array(
    '#type' => 'actions'
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update')
  );
  return $form;
}

/**
 * Form submission handler for locale_translation_status().
 */
function locale_translation_status_form_submit($form, &$form_state) {
  module_load_include('fetch.inc', 'locale');
  $langcodes = array_filter($form_state['values']['langcodes']);

  // Set the translation import options. This determines if existing
  // translations will be overwritten by imported strings.
  $options = _locale_translation_default_update_options();

  // If the status was updated recently we can immediately start fetching the
  // translation updates. If the status is expired we clear it an run a batch to
  // update the status and then fetch the translation updates.
  $last_checked = state()->get('locale.translation_last_checked');
  if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
    locale_translation_clear_status();
    $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
    batch_set($batch);
  }
  else {
    $batch = locale_translation_batch_fetch_build(array(), $langcodes, $options);
    batch_set($batch);
  }
656 657 658 659
}

/**
 * Default theme function for translation edit form.
660
 */
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
function theme_locale_translate_edit_form_strings($variables) {
  $output = '';
  $form = $variables['form'];
  $header = array(
    t('Source string'),
    t('Translation for @language', array('@language' => $form['#language'])),
  );
  $rows = array();
  foreach (element_children($form) as $lid) {
    $string = $form[$lid];
    if ($string['plural']['#value']) {
      $source = drupal_render($string['original_singular']) . '<br />' . drupal_render($string['original_plural']);
    }
    else {
      $source = drupal_render($string['original']);
    }
    $source .= empty($string['context']) ? '' : '<br /><small>' . t('In Context') . ':&nbsp;' . $string['context']['#value'] . '</small>';
    $rows[] = array(
      array('data' => $source),
      array('data' => $string['translations']),
    );
682
  }
683 684 685 686 687 688 689 690
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'empty' => t('No strings available.'),
    'attributes' => array('class' => array('locale-translate-edit-table')),
  ));
  $output .= theme('pager');
  return $output;
691
}