Révision 9faa5de0
Ajouté par Assos Assos il y a presque 3 ans
- ID 9faa5de0ee5c940f7ee0fa98ecd32c0b997b9d0e
- Parent bad4e148
drupal7/sites/all/modules/i18n/i18n_string/i18n_string.pages.inc | ||
---|---|---|
459 | 459 |
} |
460 | 460 |
return $output; |
461 | 461 |
} |
462 |
|
|
463 |
/** |
|
464 |
* String search & translate screen. |
|
465 |
* |
|
466 |
* Almost exactly the same as the core locale module's implementation, but |
|
467 |
* taking i18n_string_source_language into account for the languages column. |
|
468 |
*/ |
|
469 |
function i18n_string_locale_translate_seek_screen() { |
|
470 |
// Add CSS. |
|
471 |
drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css'); |
|
472 |
|
|
473 |
$elements = drupal_get_form('locale_translation_filter_form'); |
|
474 |
$output = drupal_render($elements); |
|
475 |
$output .= _i18n_string_locale_translate_seek(); |
|
476 |
return $output; |
|
477 |
} |
|
478 |
|
|
479 |
/** |
|
480 |
* Perform a string search and display results in a table |
|
481 |
*/ |
|
482 |
function _i18n_string_locale_translate_seek() { |
|
483 |
$output = ''; |
|
484 |
|
|
485 |
// We have at least one criterion to match |
|
486 |
if (!($query = _locale_translate_seek_query())) { |
|
487 |
$query = array( |
|
488 |
'translation' => 'all', |
|
489 |
'group' => 'all', |
|
490 |
'language' => 'all', |
|
491 |
'string' => '', |
|
492 |
); |
|
493 |
} |
|
494 |
|
|
495 |
$sql_query = db_select('locales_source', 's'); |
|
496 |
|
|
497 |
$limit_language = NULL; |
|
498 |
if ($query['language'] != 'en' && $query['language'] != 'all') { |
|
499 |
$sql_query->leftJoin('locales_target', 't', "t.lid = s.lid AND t.language = :langcode", array(':langcode' => $query['language'])); |
|
500 |
$limit_language = $query['language']; |
|
501 |
} |
|
502 |
else { |
|
503 |
$sql_query->leftJoin('locales_target', 't', 't.lid = s.lid'); |
|
504 |
} |
|
505 |
|
|
506 |
$sql_query->fields('s', array('source', 'location', 'context', 'lid', 'textgroup')); |
|
507 |
$sql_query->fields('t', array('translation', 'language')); |
|
508 |
|
|
509 |
// Compute LIKE section. |
|
510 |
switch ($query['translation']) { |
|
511 |
case 'translated': |
|
512 |
$sql_query->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE'); |
|
513 |
$sql_query->orderBy('t.translation', 'DESC'); |
|
514 |
break; |
|
515 |
case 'untranslated': |
|
516 |
$sql_query->condition(db_and() |
|
517 |
->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE') |
|
518 |
->isNull('t.translation') |
|
519 |
); |
|
520 |
$sql_query->orderBy('s.source'); |
|
521 |
break; |
|
522 |
case 'all' : |
|
523 |
default: |
|
524 |
$condition = db_or() |
|
525 |
->condition('s.source', '%' . db_like($query['string']) . '%', 'LIKE'); |
|
526 |
if ($query['language'] != 'en') { |
|
527 |
// Only search in translations if the language is not forced to English. |
|
528 |
$condition->condition('t.translation', '%' . db_like($query['string']) . '%', 'LIKE'); |
|
529 |
} |
|
530 |
$sql_query->condition($condition); |
|
531 |
break; |
|
532 |
} |
|
533 |
|
|
534 |
// Add a condition on the text group. |
|
535 |
if (!empty($query['group']) && $query['group'] != 'all') { |
|
536 |
$sql_query->condition('s.textgroup', $query['group']); |
|
537 |
} |
|
538 |
|
|
539 |
$sql_query = $sql_query->extend('PagerDefault')->limit(50); |
|
540 |
$locales = $sql_query->execute(); |
|
541 |
|
|
542 |
$groups = module_invoke_all('locale', 'groups'); |
|
543 |
$header = array(t('Text group'), t('String'), t('Context'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2')); |
|
544 |
|
|
545 |
$strings = array(); |
|
546 |
foreach ($locales as $locale) { |
|
547 |
if (!isset($strings[$locale->lid])) { |
|
548 |
$strings[$locale->lid] = array( |
|
549 |
'group' => $locale->textgroup, |
|
550 |
'languages' => array(), |
|
551 |
'location' => $locale->location, |
|
552 |
'source' => $locale->source, |
|
553 |
'context' => $locale->context, |
|
554 |
); |
|
555 |
} |
|
556 |
if (isset($locale->language)) { |
|
557 |
$strings[$locale->lid]['languages'][$locale->language] = $locale->translation; |
|
558 |
} |
|
559 |
} |
|
560 |
|
|
561 |
$rows = array(); |
|
562 |
foreach ($strings as $lid => $string) { |
|
563 |
$rows[] = array( |
|
564 |
$groups[$string['group']], |
|
565 |
array('data' => check_plain(truncate_utf8($string['source'], 150, FALSE, TRUE)) . '<br /><small>' . $string['location'] . '</small>'), |
|
566 |
$string['context'], |
|
567 |
array('data' => _i18n_string_locale_translate_language_list($string, $limit_language), 'align' => 'center'), |
|
568 |
array('data' => l(t('edit'), "admin/config/regional/translate/edit/$lid", array('query' => drupal_get_destination())), 'class' => array('nowrap')), |
|
569 |
array('data' => l(t('delete'), "admin/config/regional/translate/delete/$lid", array('query' => drupal_get_destination())), 'class' => array('nowrap')), |
|
570 |
); |
|
571 |
} |
|
572 |
|
|
573 |
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No strings available.'))); |
|
574 |
$output .= theme('pager'); |
|
575 |
|
|
576 |
return $output; |
|
577 |
} |
|
578 |
|
|
579 |
/** |
|
580 |
* List languages in search result table. |
|
581 |
*/ |
|
582 |
function _i18n_string_locale_translate_language_list($string, $limit_language) { |
|
583 |
// Add CSS. |
|
584 |
drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css'); |
|
585 |
|
|
586 |
// Include both translated and not yet translated target languages in the |
|
587 |
// list. The source language is English for built-in strings and the default |
|
588 |
// language for other strings. |
|
589 |
$languages = language_list(); |
|
590 |
$default = language_default(); |
|
591 |
$omit = $string['group'] == 'default' ? 'en' : variable_get('i18n_string_source_language', $default->language); |
|
592 |
unset($languages[$omit]); |
|
593 |
$output = ''; |
|
594 |
foreach ($languages as $langcode => $language) { |
|
595 |
if (!$limit_language || $limit_language == $langcode) { |
|
596 |
$output .= (!empty($string['languages'][$langcode])) ? $langcode . ' ' : "<em class=\"locale-untranslated\">$langcode</em> "; |
|
597 |
} |
|
598 |
} |
|
599 |
|
|
600 |
return $output; |
|
601 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules