Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.199 diff -u -p -r1.199 locale.inc --- includes/locale.inc 6 Jan 2009 13:20:17 -0000 1.199 +++ includes/locale.inc 3 Feb 2009 20:48:03 -0000 @@ -535,8 +535,11 @@ function locale_translate_overview_scree * String search screen. */ function locale_translate_seek_screen() { - $output = _locale_translate_seek(); - $output .= drupal_get_form('locale_translate_seek_form'); + // Add CSS + drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css', array('preprocess' => FALSE)); + + $output = drupal_get_form('locale_translation_filter_form'); + $output .= _locale_translate_seek(); return $output; } @@ -589,6 +592,125 @@ function locale_translate_seek_form() { */ /** + * List locale translation filters that can be applied. + */ +function locale_translation_filters() { + $filters = array(); + + // Get all languages, except English + $languages = locale_language_list('name', TRUE); + unset($languages['en']); + + $filters['string'] = array( + 'title' => t('String contains'), + 'description' => t('Leave blank to show all strings. The search is case sensitive.'), + ); + + $filters['language'] = array( + 'title' => t('Language'), + //'where' => "??", + 'options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages), + ); + + $filters['translation'] = array( + 'title' => t('Search in'), + 'options' => array('all' => t('Both translated and untranslated strings'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')), + ); + + $groups = module_invoke_all('locale', 'groups'); + $filters['group'] = array( + 'title' => t('Limit search to'), + 'options' => array_merge(array('all' => t('All text groups')), $groups), + ); + + return $filters; +} + +/** + * Return form for locale translation filters. + * + * @ingroup forms + */ +function locale_translation_filter_form() { + $session = &$_SESSION['locale_translation_filter']; + $session = is_array($session) ? $session : array(); + $filters = locale_translation_filters(); + + $form['filters'] = array( + '#type' => 'fieldset', + '#title' => t('Filter translatable strings'), + '#theme' => 'dblog_filters', + '#collapsible' => TRUE, + '#collapsed' => empty($session), + ); + foreach ($filters as $key => $filter) { + // Special case for 'string' filter. + if ($key == 'string') { + $form['filters']['status']['string'] = array( + '#type' => 'textfield', + '#title' => $filter['title'], + '#description' => $filter['description'], + ); + } + else { + $form['filters']['status'][$key] = array( + '#title' => $filter['title'], + '#type' => 'select', + '#multiple' => FALSE, + '#size' => 0, + '#options' => $filter['options'], + ); + } + if (!empty($session[$key])) { + $form['filters']['status'][$key]['#default_value'] = $session[$key]; + } + } + + $form['filters']['buttons']['submit'] = array( + '#type' => 'submit', + '#value' => t('Filter'), + ); + if (!empty($session)) { + $form['filters']['buttons']['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset') + ); + } + + return $form; +} + +/** + * Validate result from locale translation filter form. + */ +function locale_translation_filter_form_validate($form, &$form_state) { + if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['language']) && empty($form_state['values']['group'])) { + form_set_error('type', t('You must select something to filter by.')); + } +} + +/** + * Process result from locale translation filter form. + */ +function locale_translation_filter_form_submit($form, &$form_state) { + $op = $form_state['values']['op']; + $filters = locale_translation_filters(); + switch ($op) { + case t('Filter'): + foreach ($filters as $name => $filter) { + if (isset($form_state['values'][$name])) { + $_SESSION['locale_translation_filter'][$name] = $form_state['values'][$name]; + } + } + break; + case t('Reset'): + $_SESSION['locale_translation_filter'] = array(); + break; + } + return 'admin/build/translate/translate'; +} + +/** * @defgroup locale-translate-import Translation import screen. * @{ */ @@ -1984,90 +2106,98 @@ function _locale_translate_seek() { $output = ''; // We have at least one criterion to match - if ($query = _locale_translate_seek_query()) { - $join = "SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid "; + if (!($query = _locale_translate_seek_query())) { + $query = array( + 'translation' => 'all', + 'group' => 'all', + 'language' => 'all', + 'string' => '', + ); + } + + $join = "SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid "; + $arguments = array(); + + $limit_language = FALSE; + // Compute LIKE section + switch ($query['translation']) { + case 'translated': + $where = "WHERE (t.translation LIKE ?)"; + $orderby = "ORDER BY t.translation"; + $arguments[] = '%'. $query['string'] .'%'; + break; + case 'untranslated': + $where = "WHERE (s.source LIKE ? AND t.translation IS NULL)"; + $orderby = "ORDER BY s.source"; + $arguments[] = '%'. $query['string'] .'%'; + break; + case 'all' : + default: + $where = "WHERE (s.source LIKE ? OR t.translation LIKE ?)"; + $orderby = ''; + $arguments[] = '%'. $query['string'] .'%'; + $arguments[] = '%'. $query['string'] .'%'; + break; + } + $grouplimit = ''; + if (!empty($query['group']) && $query['group'] != 'all') { + $grouplimit = " AND s.textgroup = ?"; + $arguments[] = $query['group']; + } - $arguments = array(); - $limit_language = FALSE; - // Compute LIKE section - switch ($query['translation']) { - case 'translated': - $where = "WHERE (t.translation LIKE ?)"; - $orderby = "ORDER BY t.translation"; - $arguments[] = '%'. $query['string'] .'%'; - break; - case 'untranslated': - $where = "WHERE (s.source LIKE ? AND t.translation IS NULL)"; - $orderby = "ORDER BY s.source"; - $arguments[] = '%'. $query['string'] .'%'; - break; - case 'all' : - default: - $where = "WHERE (s.source LIKE ? OR t.translation LIKE ?)"; - $orderby = ''; - $arguments[] = '%'. $query['string'] .'%'; - $arguments[] = '%'. $query['string'] .'%'; - break; - } - $grouplimit = ''; - if (!empty($query['group']) && $query['group'] != 'all') { - $grouplimit = " AND s.textgroup = ?"; - $arguments[] = $query['group']; - } + switch ($query['language']) { + // Force search in source strings + case "en": + $sql = $join . " WHERE s.source LIKE ? $grouplimit ORDER BY s.source"; + $arguments = array('%' . $query['string'] . '%'); // $where is not used, discard its arguments + if (!empty($grouplimit)) { + $arguments[] = $query['group']; + } + break; + // Search in all languages + case "all": + $sql = "$join $where $grouplimit $orderby"; + break; + // Some different language + default: + $sql = "$join AND t.language = ? $where $grouplimit $orderby"; + array_unshift($arguments, $query['language']); + // Don't show translation flags for other languages, we can't see them with this search. + $limit_language = $query['language']; + } - switch ($query['language']) { - // Force search in source strings - case "en": - $sql = $join . " WHERE s.source LIKE ? $grouplimit ORDER BY s.source"; - $arguments = array('%' . $query['string'] . '%'); // $where is not used, discard its arguments - if (!empty($grouplimit)) { - $arguments[] = $query['group']; - } - break; - // Search in all languages - case "all": - $sql = "$join $where $grouplimit $orderby"; - break; - // Some different language - default: - $sql = "$join AND t.language = ? $where $grouplimit $orderby"; - array_unshift($arguments, $query['language']); - // Don't show translation flags for other languages, we can't see them with this search. - $limit_language = $query['language']; - } - - $result = pager_query($sql, 50, 0, NULL, $arguments); - - $groups = module_invoke_all('locale', 'groups'); - $header = array(t('Text group'), t('String'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2')); - $arr = array(); - while ($locale = db_fetch_object($result)) { - $arr[$locale->lid]['group'] = $groups[$locale->textgroup]; - $arr[$locale->lid]['languages'][$locale->language] = $locale->translation; - $arr[$locale->lid]['location'] = $locale->location; - $arr[$locale->lid]['source'] = $locale->source; - } - $rows = array(); - foreach ($arr as $lid => $value) { - $rows[] = array( - $value['group'], - array('data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) . '
' . $value['location'] . ''), - array('data' => _locale_translate_language_list($value['languages'], $limit_language), 'align' => 'center'), - array('data' => l(t('edit'), "admin/build/translate/edit/$lid"), 'class' => 'nowrap'), - array('data' => l(t('delete'), "admin/build/translate/delete/$lid"), 'class' => 'nowrap'), - ); - } + $result = pager_query($sql, 50, 0, NULL, $arguments); - if (count($rows)) { - $output .= theme('table', $header, $rows); - if ($pager = theme('pager', NULL, 50)) { - $output .= $pager; - } - } - else { - $output .= t('No strings found for your search.'); + $groups = module_invoke_all('locale', 'groups'); + $header = array(t('Text group'), t('String'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2')); + $arr = array(); + while ($locale = db_fetch_object($result)) { + $arr[$locale->lid]['group'] = $groups[$locale->textgroup]; + $arr[$locale->lid]['languages'][$locale->language] = $locale->translation; + $arr[$locale->lid]['location'] = $locale->location; + $arr[$locale->lid]['source'] = $locale->source; + } + $rows = array(); + foreach ($arr as $lid => $value) { + $rows[] = array( + $value['group'], + array('data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) . '
' . $value['location'] . ''), + array('data' => _locale_translate_language_list($value['languages'], $limit_language), 'align' => 'center'), + array('data' => l(t('edit'), "admin/build/translate/edit/$lid", array('query' => drupal_get_destination())), 'class' => 'nowrap'), + array('data' => l(t('delete'), "admin/build/translate/delete/$lid", array('query' => drupal_get_destination())), 'class' => 'nowrap'), + ); + } + + if (count($rows)) { + $output .= theme('table', $header, $rows); + if ($pager = theme('pager', NULL, 50)) { + drupal_set_message($pager); + $output .= $pager; } } + else { + $output .= t('No strings found for your search.'); + } return $output; } @@ -2081,8 +2211,8 @@ function _locale_translate_seek_query() $query = array(); $fields = array('string', 'language', 'translation', 'group'); foreach ($fields as $field) { - if (isset($_REQUEST[$field])) { - $query[$field] = $_REQUEST[$field]; + if (isset($_SESSION['locale_translation_filter'][$field])) { + $query[$field] = $_SESSION['locale_translation_filter'][$field]; } } } Index: modules/locale/locale.css =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.css,v retrieving revision 1.1 diff -u -p -r1.1 locale.css --- modules/locale/locale.css 14 Aug 2006 07:14:49 -0000 1.1 +++ modules/locale/locale.css 3 Feb 2009 20:48:03 -0000 @@ -4,3 +4,18 @@ font-style: normal; text-decoration: line-through; } + +#edit-language-wrapper, #edit-translation-wrapper, #edit-group-wrapper { + float: left; /* LTR */ + padding-right: .8em; /* LTR */ + margin: 0.1em; + /** + * In Opera 9, DOM elements with the property of "overflow: auto" + * will partially hide its contents with unnecessary scrollbars when + * its immediate child is floated without an explicit width set. + */ + width: 15em; +} +#locale-translation-filter-form .form-item select.form-select { + width: 100%; +} Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.234 diff -u -p -r1.234 locale.module --- modules/locale/locale.module 16 Dec 2008 23:57:32 -0000 1.234 +++ modules/locale/locale.module 3 Feb 2009 20:48:03 -0000 @@ -135,8 +135,8 @@ function locale_menu() { 'weight' => 0, 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/build/translate/search'] = array( - 'title' => 'Search', + $items['admin/build/translate/translate'] = array( + 'title' => 'Translate', 'weight' => 10, 'type' => MENU_LOCAL_TASK, 'page callback' => 'locale_translate_seek_screen', // search results and form concatenated