Skip to content

Commit 837715f

Browse files
kowskevin-brown
authored andcommitted
Fixes select2#2278
Instead of instantly applying the translations, add them to an array. That way users can include the language files that their site supports and apply the required language using $.extend($.fn.select2.defaults, $.fn.select2.locales["nl"]); Signed-off-by: Kevin Brown <kevin@kevinbrown.in>
1 parent 79b5bf6 commit 837715f

45 files changed

Lines changed: 59 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

select2.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,14 +3425,6 @@ the specific language governing permissions and limitations under the Apache Lic
34253425
},
34263426
formatResultCssClass: function(data) {return data.css;},
34273427
formatSelectionCssClass: function(data, container) {return undefined;},
3428-
formatMatches: function (matches) { if (matches === 1) { return "One result is available, press enter to select it."; } return matches + " results are available, use up and down arrow keys to navigate."; },
3429-
formatNoMatches: function () { return "No matches found"; },
3430-
formatAjaxError: function (jqXHR, textStatus, errorThrown) { return "Loading failed"; },
3431-
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1? "" : "s"); },
3432-
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
3433-
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3434-
formatLoadMore: function (pageNumber) { return "Loading more results…"; },
3435-
formatSearching: function () { return "Searching…"; },
34363428
minimumResultsForSearch: 0,
34373429
minimumInputLength: 0,
34383430
maximumInputLength: null,
@@ -3471,6 +3463,21 @@ the specific language governing permissions and limitations under the Apache Lic
34713463
}
34723464
};
34733465

3466+
$.fn.select2.locales = [];
3467+
3468+
$.fn.select2.locales['en'] = {
3469+
formatMatches: function (matches) { if (matches === 1) { return "One result is available, press enter to select it."; } return matches + " results are available, use up and down arrow keys to navigate."; },
3470+
formatNoMatches: function () { return "No matches found"; },
3471+
formatAjaxError: function (jqXHR, textStatus, errorThrown) { return "Loading failed"; },
3472+
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1 ? "" : "s"); },
3473+
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1 ? "" : "s"); },
3474+
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
3475+
formatLoadMore: function (pageNumber) { return "Loading more results…"; },
3476+
formatSearching: function () { return "Searching…"; },
3477+
};
3478+
3479+
$.extend($.fn.select2.defaults, $.fn.select2.locales['en']);
3480+
34743481
$.fn.select2.ajaxDefaults = {
34753482
transport: $.ajax,
34763483
params: {

select2_locale_ar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function ($) {
77
"use strict";
88

9-
$.extend($.fn.select2.defaults, {
9+
$.fn.select2.locales['ar'] = {
1010
formatNoMatches: function () { return "لم يتم العثور على مطابقات"; },
1111
formatInputTooShort: function (input, min) { var n = min - input.length; if (n == 1){ return "الرجاء إدخال حرف واحد على الأكثر"; } return n == 2 ? "الرجاء إدخال حرفين على الأكثر" : "الرجاء إدخال " + n + " على الأكثر"; },
1212
formatInputTooLong: function (input, max) { var n = input.length - max; if (n == 1){ return "الرجاء إدخال حرف واحد على الأقل"; } return n == 2 ? "الرجاء إدخال حرفين على الأقل" : "الرجاء إدخال " + n + " على الأقل "; },

select2_locale_bg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(function ($) {
88
"use strict";
99

10-
$.extend($.fn.select2.defaults, {
10+
$.fn.select2.locales['bg'] = {
1111
formatNoMatches: function () { return "Няма намерени съвпадения"; },
1212
formatInputTooShort: function (input, min) { var n = min - input.length; return "Моля въведете още " + n + " символ" + (n > 1 ? "а" : ""); },
1313
formatInputTooLong: function (input, max) { var n = input.length - max; return "Моля въведете с " + n + " по-малко символ" + (n > 1 ? "а" : ""); },

select2_locale_ca.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function ($) {
77
"use strict";
88

9-
$.extend($.fn.select2.defaults, {
9+
$.fn.select2.locales['ca'] = {
1010
formatNoMatches: function () { return "No s'ha trobat cap coincidència"; },
1111
formatInputTooShort: function (input, min) { var n = min - input.length; return "Introduïu " + n + " caràcter" + (n == 1 ? "" : "s") + " més"; },
1212
formatInputTooLong: function (input, max) { var n = input.length - max; return "Introduïu " + n + " caràcter" + (n == 1? "" : "s") + "menys"; },

select2_locale_cs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
3: function() { return "tři"; },
1313
4: function() { return "čtyři"; }
1414
}
15-
$.extend($.fn.select2.defaults, {
15+
$.fn.select2.locales['cs'] = {
1616
formatNoMatches: function () { return "Nenalezeny žádné položky"; },
1717
formatInputTooShort: function (input, min) {
1818
var n = min - input.length;

select2_locale_da.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function ($) {
77
"use strict";
88

9-
$.extend($.fn.select2.defaults, {
9+
$.fn.select2.locales['da'] = {
1010
formatNoMatches: function () { return "Ingen resultater fundet"; },
1111
formatInputTooShort: function (input, min) { var n = min - input.length; return "Angiv venligst " + n + " tegn mere"; },
1212
formatInputTooLong: function (input, max) { var n = input.length - max; return "Angiv venligst " + n + " tegn mindre"; },

select2_locale_de.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(function ($) {
55
"use strict";
66

7-
$.extend($.fn.select2.defaults, {
7+
$.fn.select2.locales['de'] = {
88
formatNoMatches: function () { return "Keine Übereinstimmungen gefunden"; },
99
formatInputTooShort: function (input, min) { var n = min - input.length; return "Bitte " + n + " Zeichen mehr eingeben"; },
1010
formatInputTooLong: function (input, max) { var n = input.length - max; return "Bitte " + n + " Zeichen weniger eingeben"; },

select2_locale_el.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function ($) {
77
"use strict";
88

9-
$.extend($.fn.select2.defaults, {
9+
$.fn.select2.locales['el'] = {
1010
formatNoMatches: function () { return "Δεν βρέθηκαν αποτελέσματα"; },
1111
formatInputTooShort: function (input, min) { var n = min - input.length; return "Παρακαλούμε εισάγετε " + n + " περισσότερο" + (n > 1 ? "υς" : "") + " χαρακτήρ" + (n > 1 ? "ες" : "α"); },
1212
formatInputTooLong: function (input, max) { var n = input.length - max; return "Παρακαλούμε διαγράψτε " + n + " χαρακτήρ" + (n > 1 ? "ες" : "α"); },

select2_locale_en.js.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function ($) {
77
"use strict";
88

9-
$.extend($.fn.select2.defaults, {
9+
$.fn.select2.locales['en'] = {
1010
formatMatches: function (matches) { if (matches === 1) { return "One result is available, press enter to select it."; } return matches + " results are available, use up and down arrow keys to navigate."; },
1111
formatNoMatches: function () { return "No matches found"; },
1212
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1 ? "" : "s"); },

select2_locale_es.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(function ($) {
55
"use strict";
66

7-
$.extend($.fn.select2.defaults, {
7+
$.fn.select2.locales['es'] = {
88
formatNoMatches: function () { return "No se encontraron resultados"; },
99
formatInputTooShort: function (input, min) { var n = min - input.length; return "Por favor, introduzca " + n + " car" + (n == 1? "ácter" : "acteres"); },
1010
formatInputTooLong: function (input, max) { var n = input.length - max; return "Por favor, elimine " + n + " car" + (n == 1? "ácter" : "acteres"); },

0 commit comments

Comments
 (0)