argerim / select2-rails

Integrate Select2 javascript library with Rails asset pipeline
https://github.com/argerim/select2-rails
965 stars 374 forks source link

Localizaton is not working in general #187

Closed fontanm closed 5 years ago

fontanm commented 5 years ago

I have figured out today that this gem uses select2 in version 3.5.4 that has big flaw in its localization module - you cannot really work with multiple languages as select will always use the last included

this is due to the two facts

  1. every localization file contains following line of code
    $.extend($.fn.select2.defaults, $.fn.select2.locales['cs']);

    i.e $.fn.select2.defaults gets overwritten by the latest included file

and

2) following piece from select2.js:1054:

if (opts.language != null) {
                var lang = opts.language;
                // formatNoMatches -> language.noMatches
                if ($.isFunction(lang.noMatches)) {
                    opts.formatNoMatches = lang.noMatches;
                }

contains two major flaws:

  1. var lang = opts.language; will not result in expected object with translations but with string causing all subsequent calls of ($.isFunction(lang.noMatches) fail. this may be fixed by changing this line to var lang = $.fn.select2.locales[opts.language];
  2. but it won't help anyway as locale files do not contain definition of noMatches function but (at that point obsolete) formatNoMatches so this calls for modifying all subsequent parts of this section

so to summarize this - it will not work as expected unless you hard fix the underlaying select2.js