Commit 2a8ec5ea authored by Dries's avatar Dries

- Patch #1222072 by Gábor Hojtsy: Split translation editing functionality out...

- Patch #1222072 by Gábor Hojtsy: Split translation editing functionality out of locale.admin.inc and locale.inc.
parent 9ecb9a89
......@@ -1688,129 +1688,6 @@ function _locale_export_remove_plural($entry) {
* @} End of "locale-api-import-export"
*/
/**
* @defgroup locale-api-seek Translation search API
* @{
* Functions to search in translation files.
*
* These functions provide the functionality to search for specific
* translations.
*/
/**
* Perform a string search and display results in a table
*/
function _locale_translate_seek() {
$output = '';
// We have at least one criterion to match
if (!($query = _locale_translate_seek_query())) {
$query = array(
'translation' => 'all',
'group' => 'all',
'language' => 'all',
'string' => '',
);
}
$sql_query = db_select('locales_source', 's');
$sql_query->leftJoin('locales_target', 't', 't.lid = s.lid');
$sql_query->fields('s', array('source', 'location', 'context', 'lid', 'textgroup'));
$sql_query->fields('t', array('translation', 'language'));
// Compute LIKE section.
switch ($query['translation']) {
case 'translated':
$sql_query->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE');
$sql_query->orderBy('t.translation', 'DESC');
break;
case 'untranslated':
$sql_query->condition(db_and()
->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE')
->isNull('t.translation')
);
$sql_query->orderBy('s.source');
break;
case 'all' :
default:
$condition = db_or()
->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE');
if ($query['language'] != 'en') {
// Only search in translations if the language is not forced to English.
$condition->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE');
}
$sql_query->condition($condition);
break;
}
$limit_language = NULL;
if ($query['language'] != 'en' && $query['language'] != 'all') {
$sql_query->condition('language', $query['language']);
$limit_language = $query['language'];
}
// Add a condition on the text group.
if (!empty($query['group']) && $query['group'] != 'all') {
$sql_query->condition('s.textgroup', $query['group']);
}
$sql_query = $sql_query->extend('PagerDefault')->limit(50);
$locales = $sql_query->execute();
$groups = module_invoke_all('locale', 'groups');
$header = array(t('Text group'), t('String'), t('Context'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2'));
$strings = array();
foreach ($locales as $locale) {
if (!isset($strings[$locale->lid])) {
$strings[$locale->lid] = array(
'group' => $locale->textgroup,
'languages' => array(),
'location' => $locale->location,
'source' => $locale->source,
'context' => $locale->context,
);
}
if (isset($locale->language)) {
$strings[$locale->lid]['languages'][$locale->language] = $locale->translation;
}
}
$rows = array();
foreach ($strings as $lid => $string) {
$rows[] = array(
$groups[$string['group']],
array('data' => check_plain(truncate_utf8($string['source'], 150, FALSE, TRUE)) . '<br /><small>' . $string['location'] . '</small>'),
$string['context'],
array('data' => _locale_translate_language_list($string['languages'], $limit_language), 'align' => 'center'),
array('data' => l(t('edit'), "admin/config/regional/translate/edit/$lid", array('query' => drupal_get_destination())), 'class' => array('nowrap')),
array('data' => l(t('delete'), "admin/config/regional/translate/delete/$lid", array('query' => drupal_get_destination())), 'class' => array('nowrap')),
);
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No strings available.')));
$output .= theme('pager');
return $output;
}
/**
* Build array out of search criteria specified in request variables
*/
function _locale_translate_seek_query() {
$query = &drupal_static(__FUNCTION__);
if (!isset($query)) {
$query = array();
$fields = array('string', 'language', 'translation', 'group');
foreach ($fields as $field) {
if (isset($_SESSION['locale_translation_filter'][$field])) {
$query[$field] = $_SESSION['locale_translation_filter'][$field];
}
}
}
return $query;
}
/**
* Force the JavaScript translation file(s) to be refreshed.
*
......@@ -1974,28 +1851,6 @@ function _locale_rebuild_js($langcode = NULL) {
}
}
/**
* List languages in search result table
*/
function _locale_translate_language_list($translation, $limit_language) {
// Add CSS.
drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
$languages = language_list();
unset($languages['en']);
$output = '';
foreach ($languages as $langcode => $language) {
if (!$limit_language || $limit_language == $langcode) {
$output .= (!empty($translation[$langcode])) ? $langcode . ' ' : "<em class=\"locale-untranslated\">$langcode</em> ";
}
}
return $output;
}
/**
* @} End of "locale-api-seek"
*/
/**
* @defgroup locale-api-predefined List of predefined languages
* @{
......
This diff is collapsed.
......@@ -140,7 +140,7 @@ function locale_menu() {
'description' => 'Translate the built in interface and optionally other text.',
'page callback' => 'locale_translate_overview_screen',
'access arguments' => array('translate interface'),
'file' => 'locale.admin.inc',
'file' => 'locale.pages.inc',
'weight' => -5,
);
$items['admin/config/regional/translate/overview'] = array(
......@@ -154,7 +154,7 @@ function locale_menu() {
'type' => MENU_LOCAL_TASK,
'page callback' => 'locale_translate_seek_screen', // search results and form concatenated
'access arguments' => array('translate interface'),
'file' => 'locale.admin.inc',
'file' => 'locale.pages.inc',
);
$items['admin/config/regional/translate/import'] = array(
'title' => 'Import',
......@@ -178,14 +178,14 @@ function locale_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_translate_edit_form', 5),
'access arguments' => array('translate interface'),
'file' => 'locale.admin.inc',
'file' => 'locale.pages.inc',
);
$items['admin/config/regional/translate/delete/%'] = array(
'title' => 'Delete string',
'page callback' => 'locale_translate_delete_page',
'page arguments' => array(5),
'access arguments' => array('translate interface'),
'file' => 'locale.admin.inc',
'file' => 'locale.pages.inc',
);
// Localize date formats.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment