You are here

function i18n_string_translate_page_overview_form in Internationalization 7

Provide a core translation module like overview page for this object.

1 string reference to 'i18n_string_translate_page_overview_form'
i18n_string_translate_page_overview in i18n_string/i18n_string.pages.inc
Provide a core translation module like overview page for this object.

File

i18n_string/i18n_string.pages.inc, line 60
Internationalization (i18n) package - translatable strings reusable admin UI.

Code

function i18n_string_translate_page_overview_form($form, &$form_state, $object, $strings) {

  // Set the default item key, assume it's the first.
  $item_title = reset($strings);
  $header = array(
    'language' => t('Language'),
    'title' => t('Title'),
    'status' => t('Status'),
    'operations' => t('Operations'),
  );
  $source_language = variable_get_value('i18n_string_source_language');
  $rows = array();
  foreach (language_list() as $langcode => $language) {
    if ($langcode == $source_language) {
      $items = array(
        'language' => check_plain($language->name) . ' ' . t('(source)'),
        'title' => check_plain($item_title
          ->get_string()),
        'status' => t('original'),
        'operations' => l(t('edit'), $object
          ->get_edit_path()),
      );
    }
    else {

      // Try to figure out if this item has any of its properties translated.
      $translated = FALSE;
      foreach ($strings as $i18nstring) {
        if ($i18nstring
          ->get_translation($langcode)) {
          $translated = TRUE;
          break;
        }
      }

      // Translate the item that was requested to be displayed as title.
      $items = array(
        'language' => check_plain($language->name),
        'title' => $item_title
          ->format_translation($langcode, array(
          'sanitize default' => TRUE,
        )),
        'status' => $translated ? t('translated') : t('not translated'),
        'operations' => l(t('translate'), $object
          ->get_translate_path($langcode), array(
          'query' => drupal_get_destination(),
        )),
      );
    }
    foreach ($items as $key => $markup) {
      $rows[$langcode][$key] = $markup;

      //$form['#rows'][$langcode][$key]['#markup'] = $markup;
    }
  }

  // Build a form so it can be altered later, with all this information.
  $form['object'] = array(
    '#type' => 'value',
    '#value' => $object,
  );
  $form['source_language'] = array(
    '#type' => 'value',
    '#value' => $source_language,
  );
  $form['languages'] = array(
    '#header' => $header,
    '#rows' => $rows,
    '#theme' => 'table',
  );
  return $form;
}