You are here

function l10n_client_translate_page in Localization client 6.2

Same name and namespace in other branches
  1. 5 l10n_client.module \l10n_client_translate_page()
  2. 6 l10n_client.module \l10n_client_translate_page()
  3. 7 l10n_client.module \l10n_client_translate_page()

Menu callback. Translation pages.

These pages just list strings so they can be added to the string list for translation below the page. This can be considered a hack, since we could just implement the same UI on the page, and do away with these artifical listings, but the current UI works, so we just reuse it this way.

This includes custom textgroup support that can be used manually or by other modules.

Parameters

$display_translated: Boolean indicating whether translated or untranslated strings are displayed.

$textgroup: Internal name of textgroup to use.

$allow_translation: Boolean indicating whether translation of strings via the l10n_client UI is allowed.

1 string reference to 'l10n_client_translate_page'
l10n_client_menu in ./l10n_client.module
Implementation of hook_menu().

File

./l10n_client.module, line 141
Localization client. Provides on-page translation editing.

Code

function l10n_client_translate_page($display_translated = FALSE, $textgroup = 'default', $allow_translation = TRUE) {
  global $language;
  $header = $table = array();
  $output = '';

  // Build query to look for strings.
  $sql = "SELECT s.source, t.translation, t.language FROM {locales_source} s ";
  if ($display_translated) {
    $header = array(
      t('Source string'),
      t('Translation'),
    );
    $sql .= "INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' AND t.translation != '' ";
  }
  else {
    $header = array(
      t('Source string'),
    );
    $sql .= "LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE (t.translation IS NULL OR t.translation = '') ";
  }
  if (!empty($textgroup)) {
    $sql .= "AND s.textgroup ='" . db_escape_string($textgroup) . "' ";
  }
  $sql .= 'ORDER BY s.source';

  // For the 'default' textgroup and English language we don't allow translation.
  $allow_translation = $textgroup == 'default' && $language->language == 'en' ? FALSE : $allow_translation;
  $result = pager_query($sql, L10N_CLIENT_STRINGS, 0, NULL, $language->language);
  while ($data = db_fetch_object($result)) {
    if ($display_translated) {
      $table[] = array(
        check_plain($data->source),
        check_plain($data->translation),
      );
      if ($allow_translation) {
        l10_client_add_string_to_page($data->source, $data->translation, $textgroup);
      }
    }
    else {
      $table[] = array(
        check_plain($data->source),
      );
      if ($allow_translation) {
        l10_client_add_string_to_page($data->source, TRUE, $textgroup);
      }
    }
  }
  if (!empty($table)) {
    $output .= $pager = theme('pager', NULL, L10N_CLIENT_STRINGS);
    $output .= theme('table', $header, $table);
    $output .= $pager;
  }
  else {
    $output .= t('No strings found to translate.');
  }
  return $output;
}