Index: l10n_client.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_client/Attic/l10n_client.module,v retrieving revision 1.22.4.2 diff -u -p -r1.22.4.2 l10n_client.module --- l10n_client.module 17 Jul 2009 17:13:21 -0000 1.22.4.2 +++ l10n_client.module 17 Nov 2009 11:59:10 -0000 @@ -12,10 +12,11 @@ define('L10N_CLIENT_STRINGS', 100); /** - * Implementation of hook_menu(). + * Implement hook_menu(). */ function l10n_client_menu() { $items = array(); + // AJAX callback path for strings. $items['l10n_client/save'] = array( 'title' => 'Save string', @@ -23,7 +24,7 @@ function l10n_client_menu() { 'access arguments' => array('use on-page translation'), 'type' => MENU_CALLBACK, ); - // Helper pages to group all translated/untranslated strings. + // Helper pages to group all translated/untranslated strings. $items['locale'] = array( 'title' => 'Translate strings', 'page callback' => 'l10n_client_translate_page', @@ -45,7 +46,8 @@ function l10n_client_menu() { ); // Direct copy of the import tab from locale module to // make space for the "Reimport package" tab below. - $items['admin/international/translate/import/file'] = array( + // @todo: possibly make actions if/when core import becomes an action. + $items['admin/config/regional/translate/import/file'] = array( 'title' => 'Import file', 'page callback' => 'drupal_get_form', 'page arguments' => array('locale_translate_import_form'), @@ -53,7 +55,7 @@ function l10n_client_menu() { 'weight' => -5, 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/international/translate/import/package'] = array( + $items['admin/config/regional/translate/import/package'] = array( 'title' => 'Reimport packages', 'page callback' => 'drupal_get_form', 'page arguments' => array('l10n_client_import_package_form'), @@ -62,49 +64,39 @@ function l10n_client_menu() { 'type' => MENU_LOCAL_TASK, ); - // Direct copy of the Configure tab from locale module to - // make space for the "Localization sharing" tab below. - $items['admin/international/language/configure/language'] = array( - 'title' => 'Language negotiation', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('locale_languages_configure_form'), - 'access arguments' => array('administer languages'), - 'weight' => -10, - 'type' => MENU_DEFAULT_LOCAL_TASK, - ); - $items['admin/international/language/configure/l10n_client'] = array( - 'title' => 'Localization sharing', + $items['admin/config/regional/language/share'] = array( + 'title' => 'Sharing', 'page callback' => 'drupal_get_form', 'page arguments' => array('l10n_client_settings_form'), 'access arguments' => array('administer languages'), - 'weight' => 5, 'type' => MENU_LOCAL_TASK, + 'weight' => 40, ); return $items; } /** - * Implementation of hook_permission(). + * Implement hook_permission(). */ function l10n_client_permission() { return array( 'use on-page translation' => array( 'title' => t('Use on-page translation'), - 'description' => t('Makes it possible to translate the Drupal interface on-page.'), - ), + 'description' => t('Makes it possible to translate the Drupal interface on-page.'), + ), 'submit translations to localization server' => array( 'title' => t('Submit translations to localization server'), - 'description' => t('Allows users to submit translations to a remote localization server.'), + 'description' => t('Allows users to submit translations to a remote localization server.'), ), ); } /** - * Implementation of hook_init(). + * Implement hook_init(). */ function l10n_client_init() { global $conf, $language; - + if (user_access('use on-page translation')) { // Turn off the short string cache *in this request*, so we will // have an accurate picture of strings used to assemble the page. @@ -125,12 +117,12 @@ function l10n_client_init() { /** * 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. * @@ -145,28 +137,34 @@ function l10n_client_translate_page($dis global $language; $header = $table = array(); - $output = ''; - // Build query to look for strings. - $sql = "SELECT s.source, t.translation, t.language FROM {locales_source} s "; + $query = db_select('locales_source', 's')->extend('PagerDefault'); + $query->join('locales_target', 't', 's.lid = t.lid'); + $query->fields('s', array('source')) + ->fields('t', array('translation', 'language')) + ->condition('t.language', $language->language) + ->orderBy('s.source'); + 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 != '' "; + $query->condition('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 = '') "; + $query->condition('t.translation', ''); } if (!empty($textgroup)) { - $sql .= "AND s.textgroup ='" . db_escape_string($textgroup) . "' "; + $query->condition('s.textgroup', $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)) { + + $result = $query + ->limit( L10N_CLIENT_STRINGS) + ->execute(); + + foreach ($result as $data) { if ($display_translated) { $table[] = array(check_plain($data->source), check_plain($data->translation)); if ($allow_translation) { @@ -180,25 +178,24 @@ function l10n_client_translate_page($dis } } } - if (!empty($table)) { - $output .= ($pager = theme('pager', NULL, L10N_CLIENT_STRINGS)); - $output .= theme('table', $header, $table); - $output .= $pager; + if (!empty($table)) { + $pager = theme('pager'); + $output = $pager . theme('table', $header, $table) . $pager; } else { - $output .= t('No strings found to translate.'); + $output = t('No strings found to translate.'); } return $output; } /** - * Implementation of hook_footer(). + * Implement hook_page_alter(). * - * Output a form to the page and a list of strings used to build - * the page in JSON form. + * Output a form to the page and a list of strings used to build the page in + * JSON form. */ -function l10n_client_footer() { +function l10n_client_page_alter(&$page) { global $conf, $language; - + // Check permission and get all strings used on the page. if (user_access('use on-page translation') && ($page_strings = _l10n_client_page_strings())) { // If we have strings for the page language, restructure the data. @@ -222,7 +219,6 @@ function l10n_client_footer() { $translation_label = '

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

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