From c66581f5dbcf3457ce38497c2d0ef1f0430d0f2e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 14 Feb 2014 17:29:16 -0800 Subject: [PATCH] CRM-13929 Translate select2 stings for i18n --- CRM/Core/Form.php | 7 +++---- CRM/Core/Resources.php | 15 +++++++++++++++ js/Common.js | 6 ++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index f03b2319fa..654a46d2a1 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1260,6 +1260,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * @return HTML_QuickForm_Element */ function addEntityRef($name, $label, $props = array(), $required = FALSE) { + $config = CRM_Core_Config::singleton(); // Default properties $props['api'] = CRM_Utils_Array::value('api', $props, array()); $props['entity'] = CRM_Utils_Array::value('entity', $props, 'contact'); @@ -1284,11 +1285,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 'multiple' => !empty($props['multiple']), 'placeholder' => CRM_Utils_Array::value('placeholder', $props, $required ? ts('- select -') : ts('- none -')), 'allowClear' => !$required, - 'formatInputTooShort' => ts('Start typing a name...'), - 'formatNoMatches' => ts('None found.'), ); - if ($props['entity'] == 'contact' && CRM_Core_Config::singleton()->includeEmailInName) { - $defaults['formatInputTooShort'] = ts('Start typing a name or email...'); + if ($props['entity'] == 'contact') { + $defaults['formatInputTooShort'] = $config->includeEmailInName ? ts('Start typing a name or email...') : ts('Start typing a name...'); } $props['select'] = CRM_Utils_Array::value('select', $props, array()) + $defaults; diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 3f76348ad1..7932ea6af8 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -446,6 +446,8 @@ class CRM_Core_Resources { $url = CRM_Utils_System::url('civicrm/example', 'placeholder', FALSE, NULL, FALSE); $js = "CRM.url('init', '$url');\n"; $js .= "CRM.formatMoney('init', " . json_encode(CRM_Utils_Money::format(1234.56)) . ");"; + + $this->addLocalization($js); $this->addScript($js, $jsWeight++, $region); // Add global settings @@ -522,6 +524,19 @@ class CRM_Core_Resources { $this->addString($stringsByFile[$file]); } + /** + * Add inline scripts needed to localize js widgets + * @param string $js + */ + function addLocalization(&$js) { + $js .= ' + $.fn.select2.defaults.formatNoMatches = ' . json_encode(ts('None found.')) . '; + $.fn.select2.defaults.formatLoadMore = ' . json_encode(ts('Loading...')) . '; + $.fn.select2.defaults.formatSearching = ' . json_encode(ts('Searching...')) . '; + $.fn.select2.defaults.formatInputTooShort = ' . json_encode(ts('Enter search term...')) . '; + '; + } + /** * List of core resources we add to every CiviCRM page * diff --git a/js/Common.js b/js/Common.js index c45d48ed64..66b7c208b7 100644 --- a/js/Common.js +++ b/js/Common.js @@ -364,10 +364,12 @@ CRM.validate = CRM.validate || { }; if ($el.data('create-links')) { options.formatInputTooShort = function() { - return $el.data('select-params').formatInputTooShort + ' ' + ts('or') + '
' + CRM.utils.formatSelect2CreateLinks($el); + var txt = $el.data('select-params').formatInputTooShort || $.fn.select2.defaults.formatInputTooShort; + return txt + ' ' + ts('or') + '
' + CRM.utils.formatSelect2CreateLinks($el); }; options.formatNoMatches = function() { - return $el.data('select-params').formatNoMatches + '
' + CRM.utils.formatSelect2CreateLinks($el); + var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches; + return txt + '
' + CRM.utils.formatSelect2CreateLinks($el); }; $el.on('select2-open', function() { var $el = $(this); -- 2.25.1