The issue is, when I include the language: option to use the noResults paramter, the language reverts back to the English language. If I remove:
escapeMarkup: function (markup) { return markup; },
language: {
noResults: function (term) {
return "<a href=/'http://google.com/'>Add</a>";
}
},
it remains in the French language. I tried to initialize the default language using $.fn.select2.defaults.set('language', 'fr'); and it still remains in the English language. Is there a value I can pass in the language: parameter that can init the French language? I saw the option to use language: 'fr' but I need to include the noResults parameter.
Please help.
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/fr.js"></script>
$('form#form-edit select').select2({
ajax: {
url: site_url + '/user/ajax_get_json',
type: 'POST',
cache: false,
dataType: 'json',
delay: 250,
data: function (params) {
// Merge object2 into object1, recursively
var query = $.extend( {}, params, items );
// Query paramters will be ?search=[term]&page=[page]
return query;
},
processResults: function (data) {
return {
results: data
};
}
}
});
if ($.isArray(options.language))
is never true. It always ends up in the default language. I decided to set the default language in the ELSE as so:
else {
var baseTranslation = Translation.loadPath(
//this.defaults.amdLanguageBase + 'en'
this.defaults.amdLanguageBase + this.defaults.language
);
var customTranslation = new Translation(options.language);
customTranslation.extend(baseTranslation);
options.translations = customTranslation;
}
Now I can set the language default before calling select2() and will load the proper language.
Not sure if this is a bug or an issue but I noticed other developers asking about the same issue with no solution when using the:
language: {
noResults: function (term) {
return "<a href=/'add/user'>Add</a>";
}
}
instead of:
language: 'fr'
If anyone has any comments or feedback, please feel free to post below. Thanks