Index: l10n_client.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_client/l10n_client.module,v retrieving revision 1.13 diff -u -r1.13 l10n_client.module --- l10n_client.module 29 Apr 2008 00:32:37 -0000 1.13 +++ l10n_client.module 25 Jul 2008 16:20:39 -0000 @@ -6,6 +6,9 @@ * Localization client. Provides on-page translation editing. */ +// Number of strings for paging on translation pages +define('L10N_CLIENT_STRINGS', 100); + /** * Implementation of hook_menu(). */ @@ -18,7 +21,24 @@ 'access arguments' => array('use on-page translation'), 'type' => MENU_CALLBACK, ); - + // Helper pages to group all translated/untranslated strings + $items['locale'] = array( + 'title' => 'Translate strings', + 'page callback' => 'l10n_client_translate_page', + 'access arguments' => array('use on-page translation'), + ); + $items['locale/untranslated'] = array( + 'title' => 'Untranslated', + 'page arguments' => array('untranslated'), + 'access arguments' => array('use on-page translation'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['locale/translated'] = array( + 'title' => 'Translated', + 'page arguments' => array('translated'), + 'access arguments' => array('use on-page translation'), + 'type' => MENU_LOCAL_TASK, + ); // Direct copy of the import tab from locale module to // make space for the "Reimport package" tab below. $items['admin/build/translate/import/file'] = array( @@ -90,6 +110,60 @@ } /** + * Menu callback. Translation pages. + * + * These pages just list strings so they can be added to the string list for translation below + * + * Note: Includes 'hidden' textgroup support that can be used manually or by other modules + */ +function l10n_client_translate_page($status = 'untranslated', $textgroup = 'default', $translate = TRUE) { + global $language, $l10n_client_strings; + + $output = ''; + // Build query for strings + $sql = "SELECT s.source, t.translation, t.language FROM {locales_source} s "; + switch ($status) { + case 'translated': + $sql .= " INNER JOIN {locales_target} t ON s.lid = t.lid"; + $sql .= " WHERE t.language = '$language->language' AND t.translation != ''"; + break; + case 'untranslated': + default: + $sql .= " LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '$language->language'"; + $sql .= " WHERE (t.translation IS NULL OR t.translation = '')"; + break; + } + // Add textgroup if provided + if ($textgroup) { + $sql .= " AND s.textgroup ='" . db_escape_string($textgroup) . "'"; + } + // Order alphabetically + $sql .= ' ORDER BY s.source'; + + // For 'default' textgroup and English language we don't allow translation + $translate = ($textgroup == 'default' && $language->language == 'en') ? FALSE : $translate; + + $result = pager_query($sql, L10N_CLIENT_STRINGS); + while ($data = db_fetch_object($result)) { + // Array to display as table + $list[] = array($data->source, $data->translation); + // Add to the list for the translation tool if 'translate' enabled + if ($translate) { + $l10n_client_strings[$data->source] = (empty($data->translation) ? TRUE : $data->translation); + } + } + if (!empty($list)) { + // We add a pager above and below content to make navigation easier + $output .= $pager = theme('pager', NULL, L10N_CLIENT_STRINGS); + $output .= theme('table', array(), $list); + $output .= $pager; + } else { + $output .= t('No strings to translate'); + } + return $output; +} + +/** * Implementation of hook_footer(). * * Output a form to the page and a list of strings used to build @@ -98,65 +172,89 @@ function l10n_client_footer() { global $conf, $language; - if (user_access('use on-page translation')) { - // Get all strings used on the page. - $strings = locale(); - - if (is_array($strings) && isset($strings[$language->language])) { - // If we have strings for the page language, restructure the data. - $l10n_strings = array(); - foreach ($strings[$language->language] as $string => $translation) { - $l10n_strings[] = array($string, $translation); - } - array_multisort($l10n_strings); - // Include string selector on page. - $string_list = _l10n_client_string_list($l10n_strings); - // Include editing form on page. - $l10n_form = drupal_get_form('l10n_client_form', $l10n_strings); - // Include search form on page. - $l10n_search = drupal_get_form('l10n_client_search_form'); - - // We need this hack as JS addition does not work this late on the page. - //$l10n_json = ''; - $l10n_dom = _l10n_client_dom_strings($l10n_strings); - - // UI Labels - $string_label = '

'. t('Page Text') .'

'; - $source_label = '

'. t('Source') .'

'; - $translation_label = '

'. t('Translation to %language', array('%language' => $language->native)) .'

'; - $toggle_label = t('Translate Text'); - - - $output = " -