Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set language not working select2

<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"'

like image 871
Matheus Avatar asked Mar 05 '16 15:03

Matheus


2 Answers

<script src="libs/select2-4.0.2-rc.1/dist/js/i18n/<here-goes-language>.js"></script>

The include above was missing as Keving Brown said. As the example quoted in the question the file for spanish would be "es.js"

like image 179
Matheus Avatar answered Oct 21 '22 18:10

Matheus


Add script like this after select2 plugin

$.fn.select2.amd.define('select2/i18n/ru',[],function () {
    // Russian
    return {
        errorLoading: function () {
            return 'Результат не может быть загружен.';
        },
        inputTooLong: function (args) {
            var overChars = args.input.length - args.maximum;
            var message = 'Пожалуйста, удалите ' + overChars + ' символ';
            if (overChars >= 2 && overChars <= 4) {
                message += 'а';
            } else if (overChars >= 5) {
                message += 'ов';
            }
            return message;
        },
        inputTooShort: function (args) {
            var remainingChars = args.minimum - args.input.length;

            var message = 'Пожалуйста, введите ' + remainingChars + ' или более символов';

            return message;
        },
        loadingMore: function () {
            return 'Загружаем ещё ресурсы…';
        },
        maximumSelected: function (args) {
            var message = 'Вы можете выбрать ' + args.maximum + ' элемент';

            if (args.maximum  >= 2 && args.maximum <= 4) {
                message += 'а';
            } else if (args.maximum >= 5) {
                message += 'ов';
            }

            return message;
        },
        noResults: function () {
          return 'Ничего не найдено';
        },
        searching: function () {
          return 'Поиск…';
        }
    };
});

set option

$(".js-basic-multiple").select2({
    language: "ru"
});
like image 22
SummerRain Avatar answered Oct 21 '22 16:10

SummerRain