2016-03-05 16 views
11
<select data-placeholder="Select or type" data-minlength="2" multiple = "multiple" name='arrAval' id='listAval' class="js-basic-multiple form-control" required> 

Così qui è il problema:Imposta lingua non funziona select2

Come la documentazione dice che dovrei essere in grado di impostare la lingua per questo componente:

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

Sta tornando "Nessun risultato trovato" non importa quale lingua ho impostato. Giusto per essere chiari, come in https://select2.github.io/examples.html#matcher restituisce "No se encontraron resultados" per 'la lingua: "es"'

+1

stai facendo in modo di includere il file JS per la lingua che desideri e l'opzione 'language' durante l'inizializzazione? –

+0

Avevi ragione, pensavo che sarebbe cambiato solo cambiando la sua proprietà. Ho dovuto aggiungere i riferimenti. Sto postando la risposta per questa domanda. Grazie mille. – Matheus

risposta

5

Aggiungi script come questo dopo select2 plug

$.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 'Поиск…'; 
     } 
    }; 
}); 

opzione set

$(".js-basic-multiple").select2({ 
    language: "ru" 
}); 
18
<script src="libs/select2-4.0.2-rc.1/dist/js/i18n/<here-goes-language>.js"></script> 

Il comprendono sopra mancava come detto Keving Brown. Come dimostra l'esempio citato nella questione del file per lo spagnolo sarebbe "es.js"