Set language not working select2

Viewed 40789
<select data-placeholder="Select or type" data-minlength="2" multiple = "multiple" name='arrAval' id='listAval' class="js-basic-multiple form-control" required>

So here is the issue:

As the documentation says I should be able to set language for this component:

$(".js-basic-multiple").select2({
        language: "language-wanted"
    });

It's returning "no results found" no matter which language I set. Just to be clear, as in https://select2.github.io/examples.html#matcher it returns "No se encontraron resultados" for 'language:"es"'

6 Answers

CDN scripts:

<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/i18n/[culture-name].js"></script>

If you use Webpack, you can set the default language like that (example for french) :

require('select2');
$.fn.select2.amd.define('select2/i18n/fr',[],require("select2/src/js/select2/i18n/fr"));

Additional to @SummerRain's answer, if you have loaded the language file into your page, you can use below way to set the default language for all select2, instead of one by one.

$.fn.select2.defaults.set("language", $.fn.select2.amd.require("select2/i18n/fr"));

select2 uses amd to define its dependencies as you can see from $.fn.select2.amd. "select2/i18n/fr" is the amd module name for the french language definitions.

This is the cdn for the french translation :

<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/i18n/fr.js"></script>

Related