summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiroslav2015-01-18 19:38:58 (GMT)
committerDominique CLAUSE2015-01-18 19:38:58 (GMT)
commit9fa1dbd77810abca92acc0d2758783676ad62749 (patch)
treebab253e67b850f84f5d0b2a80b206718b33dfb3b
parentb4fe1f81704647de74a6b0eee56607ccae202521 (diff)
Issue #2382785 by Dominique CLAUSE, ├▒ull, jmdeleon: Add localize to no_results and all_results labels.7.x-4.2
-rw-r--r--js/jquery.autocomplete.js21
-rw-r--r--search_autocomplete.form.add.inc4
-rw-r--r--search_autocomplete.form.configure.inc6
-rw-r--r--search_autocomplete.install47
-rw-r--r--search_autocomplete.module12
5 files changed, 65 insertions, 25 deletions
diff --git a/js/jquery.autocomplete.js b/js/jquery.autocomplete.js
index 1fd0330..c3d8a63 100644
--- a/js/jquery.autocomplete.js
+++ b/js/jquery.autocomplete.js
@@ -39,8 +39,7 @@
if (item.value == '') {
elem = $("<li class='ui-state-disabled ui-menu-item-" + first + " ui-menu-item'>" + item.label + "</li>" );
}
- elem.data("item.autocomplete", item)
- .appendTo(ul);
+ elem.data("item.autocomplete", item).appendTo(ul);
Drupal.attachBehaviors(elem);
return elem;
@@ -66,10 +65,12 @@
$.getJSON(Drupal.settings.search_autocomplete[key].datas, { q: request.term }, function (results) {
// Only return the number of values set in the settings.
if (!results.length && no_results) {
- results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
+ results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
- results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
+ if (all_results) {
+ results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
+ }
}
response(results);
});
@@ -79,10 +80,12 @@
$.getJSON(Drupal.settings.search_autocomplete[key].datas + request.term, { }, function (results) {
// Only return the number of values set in the settings.
if (!results.length && no_results) {
- results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
+ results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
- results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
+ if (all_results) {
+ results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
+ }
}
response(results);
});
@@ -91,10 +94,12 @@
else if (Drupal.settings.search_autocomplete[key].type == 'static') {
var results = $.ui.autocomplete.filter(Drupal.settings.search_autocomplete[key].datas, request.term);
if (!results.length && no_results) {
- results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, request.term))];
+ results = [jQuery.parseJSON(no_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>'))];
} else {
results.slice(0, Drupal.settings.search_autocomplete[key].max_sug);
- results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, request.term)));
+ if (all_results) {
+ results.push(jQuery.parseJSON(all_results.replace(/\[search-phrase\]/g, '<span class=\\"ui-autocomplete-field-term\\">' + request.term + '</span>')));
+ }
}
response(results);
}
diff --git a/search_autocomplete.form.add.inc b/search_autocomplete.form.add.inc
index de6bc76..284548e 100644
--- a/search_autocomplete.form.add.inc
+++ b/search_autocomplete.form.add.inc
@@ -81,7 +81,7 @@ function search_autocomplete_form_add_submit($form, &$form_state) {
'title' => $values['title'],
'selector' => $values['selector'],
'no_results' => json_encode(array( // manually add no_results default
- 'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
+ 'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -89,7 +89,7 @@ function search_autocomplete_form_add_submit($form, &$form_state) {
),
)),
'all_results' => json_encode(array( // manually add all_results default
- 'label' => 'View all results for <b>[search-phrase]</b>.',
+ 'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
diff --git a/search_autocomplete.form.configure.inc b/search_autocomplete.form.configure.inc
index bd9fdde..1a69b40 100644
--- a/search_autocomplete.form.configure.inc
+++ b/search_autocomplete.form.configure.inc
@@ -87,7 +87,7 @@ function search_autocomplete_form_configure($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Custom "view all results" message label'),
'#description' => t('This message is going to be displayed at the end of suggestion list when suggestions are found. Leave empty to disable this functionality. You can use HTML tags as well as the token [search-phrase] to replace user input.'),
- '#default_value' => $all_results->label,
+ '#default_value' => t($all_results->label),
'#maxlength' => 255,
'#required' => FALSE,
);
@@ -124,7 +124,7 @@ function search_autocomplete_form_configure($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Custom "no result" message label'),
'#description' => t('This message is going to be displayed when no suggestions can be found. Leave empty to disable this functionality. You can use HTML tags as well as the token [search-phrase] to replace user input.'),
- '#default_value' => $no_results->label,
+ '#default_value' => t($no_results->label),
'#maxlength' => 255,
'#required' => FALSE,
);
@@ -395,4 +395,4 @@ function _search_autocomplete_get_all_children($fid, &$items = array(), $depth =
_search_autocomplete_get_all_children($item->fid, $items, $depth);
}
return $items;
-} \ No newline at end of file
+}
diff --git a/search_autocomplete.install b/search_autocomplete.install
index 763e74c..2acb2f4 100644
--- a/search_autocomplete.install
+++ b/search_autocomplete.install
@@ -159,7 +159,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
- 'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
+ 'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -167,7 +167,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
- 'label' => 'View all results for <b>[search-phrase]</b>.',
+ 'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -191,7 +191,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
- 'label' => 'No results found for <b>[search-phrase]</b>.<br/> Click to perform full search.',
+ 'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -199,7 +199,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
- 'label' => 'View all results for <b>[search-phrase]</b>.',
+ 'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -223,7 +223,7 @@ function search_autocomplete_install() {
'min_char' => $trigger,
'max_sug' => $limit,
'no_results' => json_encode(array(
- 'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
+ 'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -231,7 +231,7 @@ function search_autocomplete_install() {
),
)),
'all_results' => json_encode(array(
- 'label' => 'View all results for <b>[search-phrase]</b>.',
+ 'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -395,7 +395,7 @@ function search_autocomplete_update_7410(&$sandbox) {
}
/**
- * Migrate no_results and all_resuts fields from 4.0 to 4.1 default value
+ * Migrate no_results and all_results fields from 4.0 to 4.1 default values
*/
function search_autocomplete_update_7411(&$sandbox) {
if (!db_field_exists('search_autocomplete_forms', 'no_results')) {
@@ -415,7 +415,7 @@ function search_autocomplete_update_7411(&$sandbox) {
}
db_update('search_autocomplete_forms') // Table name no longer needs {}
->fields(array('no_results' => json_encode(array(
- 'label' => 'No results found for <b>[search-phrase]</b>.<br/>Click to perform full search.',
+ 'label' => t('No results found for [search-phrase]. Click to perform full search.'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -434,7 +434,7 @@ function search_autocomplete_update_7411(&$sandbox) {
}
db_update('search_autocomplete_forms') // Table name no longer needs {}
->fields(array('all_results' => json_encode(array(
- 'label' => 'View all results for <b>[search-phrase]</b>.',
+ 'label' => t('View all results for [search-phrase].'),
'value' => '[search-phrase]',
'link' => '',
'group' => array(
@@ -442,4 +442,31 @@ function search_autocomplete_update_7411(&$sandbox) {
),
))))
->execute();
-} \ No newline at end of file
+}
+
+/**
+ * Migrate no_results and all_results fields from 4.1 to 4.2 default values
+ */
+function search_autocomplete_update_7420(&$sandbox) {
+
+ $all_fields = db_select('search_autocomplete_forms', 'sa')
+ ->fields('sa', array('fid', 'no_results', 'all_results'))
+ ->execute()
+ ->fetchAllAssoc('fid');
+
+ foreach($all_fields as $fid => $field) {
+ // Remove html tags in no_results label
+ $no_results = json_decode($field->no_results);
+ $no_results->label = strip_tags($no_results->label);
+ $all_results = json_decode($field->all_results);
+ $all_results->label = strip_tags($all_results->label);
+
+ db_update('search_autocomplete_forms')
+ ->fields(array(
+ 'no_results' => json_encode($no_results),
+ 'all_results' => json_encode($all_results)
+ ))
+ ->condition('fid', $fid, '=')
+ ->execute();
+ }
+}
diff --git a/search_autocomplete.module b/search_autocomplete.module
index b43ab7b..f60c793 100644
--- a/search_autocomplete.module
+++ b/search_autocomplete.module
@@ -70,13 +70,21 @@ function search_autocomplete_page_build() {
}
}
+ // Translate no_results label
+ $no_results = json_decode($match->no_results);
+ $no_results->label = t($no_results->label);
+
+ // Translate all_results label
+ $all_results = json_decode($match->all_results);
+ $all_results->label = t($all_results->label);
+
drupal_add_js(array('search_autocomplete' => array(
$form_id => array(
'selector' => $match->selector,
'minChars' => $match->min_char,
'max_sug' => $match->max_sug,
- 'no_results' => t($match->no_results),
- 'all_results' => t($match->all_results),
+ 'no_results' => $no_results->label ? json_encode($no_results) : null,
+ 'all_results' => $all_results->label ? json_encode($all_results) : null,
'type' => $data_source,
'datas' => $match->data_source == 'static' ? $data_static : $data_callback,
'fid' => $match->fid,