* @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');
'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;
$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
$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
*
};
if ($el.data('create-links')) {
options.formatInputTooShort = function() {
- return $el.data('select-params').formatInputTooShort + ' ' + ts('or') + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
+ var txt = $el.data('select-params').formatInputTooShort || $.fn.select2.defaults.formatInputTooShort;
+ return txt + ' ' + ts('or') + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
};
options.formatNoMatches = function() {
- return $el.data('select-params').formatNoMatches + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
+ var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches;
+ return txt + '<br />' + CRM.utils.formatSelect2CreateLinks($el);
};
$el.on('select2-open', function() {
var $el = $(this);