2014-09-26 126 views
0

我一直在嘗試更改formatInputTooShort的語言環境。更改select2 jquery插件語言環境

爲了找到正確的select2.js文件(因爲我有幾個版本的select2-rails gem),我輸入了命令RAILS_ENV=production bundle exec gem list select2-rails。然後我做了RAILS_ENV=production bundle exec gem env找到寶石的安裝位置。

所以我改變了正確的(我認爲)select2.js文件,重新啓動了我的獨角獸服務器,但locale沒有改變minimumInputLength。它仍然會顯示「請輸入一個或多個字符」,而不是我的自定義消息。

任何線索我可能做錯了什麼?

注:我使用英語。

回答

1

您可以通過執行以下重載函數重載文字:

$(#my_selector).select2({ 
    minimumInputLength: 1, 
    formatInputLength: function(){ 
    return "Enter the text you want" 
    } 
}); 
+0

沒有與V4的工作我猜! :( – 2015-09-04 20:26:55

0

$(#my_selector).select2({ 
 
    minimumInputLength: 1, 
 
    formatNoMatches: function() { return "No se encontraron resultados"; }, 
 
    formatInputTooShort: function (input, min) { 
 
    var n = min - input.length; return "Por favor, introduzca " + n + " nombre"; 
 
    }, 
 
    formatInputTooLong: function (input, max) { 
 
    var n = input.length - max; 
 
    return "Por favor, elimine " + n + " car" + (n == 1? "á" : "a") + "cter" + (n == 1? "" : "es"); 
 
    }, 
 
    formatSelectionTooBig: function (limit) { 
 
    return "Sólo puede seleccionar " + limit + " elemento" + (limit == 1 ? "" : "s"); 
 
    }, 
 
    formatLoadMore: function (pageNumber) { 
 
    return "Cargando más resultados..."; 
 
    }, 
 
    formatSearching: function() { 
 
    return "Buscando..."; 
 
    } 
 
});