From ac094bd2fef4229e397cb1fa996d4e46159b3f3d Mon Sep 17 00:00:00 2001
From: Axel Rutz <axel.rutz@clever-systems.net>
Date: Sat, 17 May 2014 14:53:16 +0200
Subject: [PATCH] Issue #2269503 by axel.rutz: Translation overview page:
 Allow exact match.

---
 .../lib/Drupal/locale/Form/TranslateFormBase.php   |    6 +++---
 .../lib/Drupal/locale/StringDatabaseStorage.php    |    2 +-
 .../Drupal/locale/Tests/LocalePluralFormatTest.php |    4 ++--
 .../lib/Drupal/locale/Tests/LocaleStringTest.php   |    7 ++++---
 .../lib/Drupal/locale/Tests/LocaleUpdateTest.php   |    2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php
index 24b378e..5233495 100644
--- a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php
+++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php
@@ -178,9 +178,9 @@ protected function translateFilters() {
     }
 
     $filters['string'] = array(
-      'title' => $this->t('String contains'),
-      'description' => $this->t('Leave blank to show all strings. The search is case sensitive.'),
-      'default' => '',
+      'title' => $this->t('String'),
+      'description' => $this->t('Use "_" to match any character, "%" to match any number of characters. Use "\_" for"_", "\%" for "%". The search is case sensitive.'),
+      'default' => '%',
     );
 
     $filters['langcode'] = array(
diff --git a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php
index 72d753a..b3f4e06 100644
--- a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php
+++ b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php
@@ -441,7 +441,7 @@ protected function dbStringSelect(array $conditions, array $options = array()) {
         $filter = $query;
       }
       foreach ($options['filters'] as $field => $string) {
-        $filter->condition($this->dbFieldTable($field) . '.' . $field, '%' . db_like($string) . '%', 'LIKE');
+        $filter->condition($this->dbFieldTable($field) . '.' . $field, $string, 'LIKE');
       }
     }
 
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php
index c8adf97..8fa4c9c 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePluralFormatTest.php
@@ -224,7 +224,7 @@ function testPluralEditExport() {
     $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 day" . LOCALE_PLURAL_DELIMITER . "@count days"))->fetchField();
     // Look up editing page for this plural string and check fields.
     $search = array(
-      'string' => '1 day',
+      'string' => '%1 day%',
       'langcode' => 'fr',
     );
     $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
@@ -238,7 +238,7 @@ function testPluralEditExport() {
 
     // Save complete translations for the string in langcode hr.
     $search = array(
-      'string' => '1 day',
+      'string' => '%1 day%',
       'langcode' => 'hr',
     );
     $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php
index a9b45ec..b6ddb1a 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php
@@ -132,11 +132,12 @@ function testStringSearchAPI() {
     $source2 = $this->buildSourceString(array('source' => $prefix . $this->randomName(100)))->save();
     $source3 = $this->buildSourceString()->save();
     // Load all source strings.
-    $strings = $this->storage->getStrings(array());
+    $filter_options['filters'] = array('source' => '%');
+    $strings = $this->storage->getStrings(array(), $filter_options);
     $this->assertEqual(count($strings), 3, 'Found 3 source strings in the database.');
     // Load all source strings matching a given string
     $filter_options['filters'] = array('source' => $prefix);
-    $strings = $this->storage->getStrings(array(), $filter_options);
+    $strings = $this->storage->getStrings(array(), $filter_options . '%');
     $this->assertEqual(count($strings), 2, 'Found 2 strings using some string filter.');
 
     // Not customized translations.
@@ -169,7 +170,7 @@ function testStringSearchAPI() {
     $this->assertEqual(count($translations), 1, 'Found 1 source string without translations.');
 
     // Load Spanish translations using string filter.
-    $filter_options['filters'] = array('source' => $prefix);
+    $filter_options['filters'] = array('source' => $prefix . '%');
     $translations = $this->storage->getTranslations(array('language' => 'es'), $filter_options);
     $this->assertEqual(count($translations), 2, 'Found 2 translations using some string filter.');
 
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
index 268f72f..491d735 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
@@ -441,7 +441,7 @@ function testEnableCustomLanguage() {
     // 'Another allowed HTML source string' was not because it contains invalid
     // HTML.
     $search = array(
-      'string' => 'HTML source string',
+      'string' => '%HTML source string%',
       'langcode' => $langcode,
       'translation' => 'all',
     );
-- 
1.7.9.5

