Added Translation object
This continues the work to get translations built into Select2.
This commit is contained in:
parent
20fcaa4449
commit
9bb993cee9
2
dist/js/i18n/en.js
vendored
2
dist/js/i18n/en.js
vendored
@ -1 +1 @@
|
|||||||
(function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/en",[],function(){return{no_results:function(){return"No results found"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}})();
|
window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/en",[],function(){return{no_results:function(){return"No results found"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}}();
|
93
dist/js/select2.amd.full.js
vendored
93
dist/js/select2.amd.full.js
vendored
@ -1,4 +1,4 @@
|
|||||||
(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }define('select2/utils',[], function () {
|
window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }define('select2/utils',[], function () {
|
||||||
var Utils = {};
|
var Utils = {};
|
||||||
|
|
||||||
Utils.Extend = function (ChildClass, SuperClass) {
|
Utils.Extend = function (ChildClass, SuperClass) {
|
||||||
@ -837,6 +837,42 @@ define('select2/selection/placeholder',[
|
|||||||
return Placeholder;
|
return Placeholder;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/translation',[
|
||||||
|
|
||||||
|
], function () {
|
||||||
|
function Translation (dict) {
|
||||||
|
this.dict = dict || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Translation.prototype.all = function () {
|
||||||
|
return this.dict;
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.get = function (key) {
|
||||||
|
return this.dict[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.extend = function (translation) {
|
||||||
|
this.dict = $.extend({}, translation.all(), this.dict);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
|
||||||
|
Translation._cache = {};
|
||||||
|
|
||||||
|
Translation.loadPath = function (path) {
|
||||||
|
if (!(path in Translation._cache)) {
|
||||||
|
var translations = require(path);
|
||||||
|
|
||||||
|
Translation._cache[path] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Translation(Translation._cache[path]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Translation;
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/data/base',[
|
define('select2/data/base',[
|
||||||
'../utils'
|
'../utils'
|
||||||
], function (Utils) {
|
], function (Utils) {
|
||||||
@ -1345,7 +1381,16 @@ define('select2/dropdown/search',[
|
|||||||
return Search;
|
return Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/i18n/en',[],function () {
|
||||||
|
return {
|
||||||
|
'no_results': function () {
|
||||||
|
return 'No results found';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/defaults',[
|
define('select2/defaults',[
|
||||||
|
'jquery',
|
||||||
'./results',
|
'./results',
|
||||||
|
|
||||||
'./selection/single',
|
'./selection/single',
|
||||||
@ -1353,6 +1398,7 @@ define('select2/defaults',[
|
|||||||
'./selection/placeholder',
|
'./selection/placeholder',
|
||||||
|
|
||||||
'./utils',
|
'./utils',
|
||||||
|
'./translation',
|
||||||
|
|
||||||
'./data/select',
|
'./data/select',
|
||||||
'./data/array',
|
'./data/array',
|
||||||
@ -1360,18 +1406,20 @@ define('select2/defaults',[
|
|||||||
'./data/tags',
|
'./data/tags',
|
||||||
|
|
||||||
'./dropdown',
|
'./dropdown',
|
||||||
'./dropdown/search'
|
'./dropdown/search',
|
||||||
], function (ResultsList,
|
|
||||||
|
'./i18n/en'
|
||||||
|
], function ($, ResultsList,
|
||||||
SingleSelection, MultipleSelection, Placeholder,
|
SingleSelection, MultipleSelection, Placeholder,
|
||||||
Utils,
|
Utils, Translation,
|
||||||
SelectData, ArrayData, AjaxData, Tags,
|
SelectData, ArrayData, AjaxData, Tags,
|
||||||
Dropdown, Search) {
|
Dropdown, Search, EnglishTranslation) {
|
||||||
function Defaults () {
|
function Defaults () {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults.prototype.apply = function (options) {
|
Defaults.prototype.apply = function (options) {
|
||||||
options = $.extend({}, options, this.defaults);
|
options = $.extend({}, this.defaults, options);
|
||||||
|
|
||||||
if (options.dataAdapter == null) {
|
if (options.dataAdapter == null) {
|
||||||
if (options.ajax) {
|
if (options.ajax) {
|
||||||
@ -1413,11 +1461,42 @@ define('select2/defaults',[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.language === 'string') {
|
||||||
|
options.language = [options.language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.isArray(options.language)) {
|
||||||
|
var languages = new Translation();
|
||||||
|
var languageNames = options.language.concat(this.defaults.language);
|
||||||
|
|
||||||
|
for (var l = 0; l < languageNames.length; l++) {
|
||||||
|
var name = languageNames[l];
|
||||||
|
var language = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to load it with the original name
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
} catch (e) {
|
||||||
|
// If we couldn't load it, check if it wasn't the full path
|
||||||
|
name = 'select2/i18n/' + name;
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
languages.extend(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.translations = languages;
|
||||||
|
} else {
|
||||||
|
options.translations = new Translations(options.language);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Defaults.prototype.reset = function () {
|
Defaults.prototype.reset = function () {
|
||||||
this.defaults = { };
|
this.defaults = {
|
||||||
|
language: ['select2/i18n/en']
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaults = new Defaults();
|
var defaults = new Defaults();
|
||||||
|
93
dist/js/select2.amd.js
vendored
93
dist/js/select2.amd.js
vendored
@ -1,4 +1,4 @@
|
|||||||
(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }define('select2/utils',[], function () {
|
window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }define('select2/utils',[], function () {
|
||||||
var Utils = {};
|
var Utils = {};
|
||||||
|
|
||||||
Utils.Extend = function (ChildClass, SuperClass) {
|
Utils.Extend = function (ChildClass, SuperClass) {
|
||||||
@ -837,6 +837,42 @@ define('select2/selection/placeholder',[
|
|||||||
return Placeholder;
|
return Placeholder;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/translation',[
|
||||||
|
|
||||||
|
], function () {
|
||||||
|
function Translation (dict) {
|
||||||
|
this.dict = dict || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Translation.prototype.all = function () {
|
||||||
|
return this.dict;
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.get = function (key) {
|
||||||
|
return this.dict[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.extend = function (translation) {
|
||||||
|
this.dict = $.extend({}, translation.all(), this.dict);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
|
||||||
|
Translation._cache = {};
|
||||||
|
|
||||||
|
Translation.loadPath = function (path) {
|
||||||
|
if (!(path in Translation._cache)) {
|
||||||
|
var translations = require(path);
|
||||||
|
|
||||||
|
Translation._cache[path] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Translation(Translation._cache[path]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Translation;
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/data/base',[
|
define('select2/data/base',[
|
||||||
'../utils'
|
'../utils'
|
||||||
], function (Utils) {
|
], function (Utils) {
|
||||||
@ -1345,7 +1381,16 @@ define('select2/dropdown/search',[
|
|||||||
return Search;
|
return Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/i18n/en',[],function () {
|
||||||
|
return {
|
||||||
|
'no_results': function () {
|
||||||
|
return 'No results found';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/defaults',[
|
define('select2/defaults',[
|
||||||
|
'jquery',
|
||||||
'./results',
|
'./results',
|
||||||
|
|
||||||
'./selection/single',
|
'./selection/single',
|
||||||
@ -1353,6 +1398,7 @@ define('select2/defaults',[
|
|||||||
'./selection/placeholder',
|
'./selection/placeholder',
|
||||||
|
|
||||||
'./utils',
|
'./utils',
|
||||||
|
'./translation',
|
||||||
|
|
||||||
'./data/select',
|
'./data/select',
|
||||||
'./data/array',
|
'./data/array',
|
||||||
@ -1360,18 +1406,20 @@ define('select2/defaults',[
|
|||||||
'./data/tags',
|
'./data/tags',
|
||||||
|
|
||||||
'./dropdown',
|
'./dropdown',
|
||||||
'./dropdown/search'
|
'./dropdown/search',
|
||||||
], function (ResultsList,
|
|
||||||
|
'./i18n/en'
|
||||||
|
], function ($, ResultsList,
|
||||||
SingleSelection, MultipleSelection, Placeholder,
|
SingleSelection, MultipleSelection, Placeholder,
|
||||||
Utils,
|
Utils, Translation,
|
||||||
SelectData, ArrayData, AjaxData, Tags,
|
SelectData, ArrayData, AjaxData, Tags,
|
||||||
Dropdown, Search) {
|
Dropdown, Search, EnglishTranslation) {
|
||||||
function Defaults () {
|
function Defaults () {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults.prototype.apply = function (options) {
|
Defaults.prototype.apply = function (options) {
|
||||||
options = $.extend({}, options, this.defaults);
|
options = $.extend({}, this.defaults, options);
|
||||||
|
|
||||||
if (options.dataAdapter == null) {
|
if (options.dataAdapter == null) {
|
||||||
if (options.ajax) {
|
if (options.ajax) {
|
||||||
@ -1413,11 +1461,42 @@ define('select2/defaults',[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.language === 'string') {
|
||||||
|
options.language = [options.language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.isArray(options.language)) {
|
||||||
|
var languages = new Translation();
|
||||||
|
var languageNames = options.language.concat(this.defaults.language);
|
||||||
|
|
||||||
|
for (var l = 0; l < languageNames.length; l++) {
|
||||||
|
var name = languageNames[l];
|
||||||
|
var language = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to load it with the original name
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
} catch (e) {
|
||||||
|
// If we couldn't load it, check if it wasn't the full path
|
||||||
|
name = 'select2/i18n/' + name;
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
languages.extend(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.translations = languages;
|
||||||
|
} else {
|
||||||
|
options.translations = new Translations(options.language);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Defaults.prototype.reset = function () {
|
Defaults.prototype.reset = function () {
|
||||||
this.defaults = { };
|
this.defaults = {
|
||||||
|
language: ['select2/i18n/en']
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaults = new Defaults();
|
var defaults = new Defaults();
|
||||||
|
93
dist/js/select2.full.js
vendored
93
dist/js/select2.full.js
vendored
@ -1,4 +1,4 @@
|
|||||||
(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }/**
|
window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }/**
|
||||||
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
||||||
* Available via the MIT or new BSD license.
|
* Available via the MIT or new BSD license.
|
||||||
* see: http://github.com/jrburke/almond for details
|
* see: http://github.com/jrburke/almond for details
|
||||||
@ -10372,6 +10372,42 @@ define('select2/selection/placeholder',[
|
|||||||
return Placeholder;
|
return Placeholder;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/translation',[
|
||||||
|
|
||||||
|
], function () {
|
||||||
|
function Translation (dict) {
|
||||||
|
this.dict = dict || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Translation.prototype.all = function () {
|
||||||
|
return this.dict;
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.get = function (key) {
|
||||||
|
return this.dict[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.extend = function (translation) {
|
||||||
|
this.dict = $.extend({}, translation.all(), this.dict);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
|
||||||
|
Translation._cache = {};
|
||||||
|
|
||||||
|
Translation.loadPath = function (path) {
|
||||||
|
if (!(path in Translation._cache)) {
|
||||||
|
var translations = require(path);
|
||||||
|
|
||||||
|
Translation._cache[path] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Translation(Translation._cache[path]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Translation;
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/data/base',[
|
define('select2/data/base',[
|
||||||
'../utils'
|
'../utils'
|
||||||
], function (Utils) {
|
], function (Utils) {
|
||||||
@ -10880,7 +10916,16 @@ define('select2/dropdown/search',[
|
|||||||
return Search;
|
return Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/i18n/en',[],function () {
|
||||||
|
return {
|
||||||
|
'no_results': function () {
|
||||||
|
return 'No results found';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/defaults',[
|
define('select2/defaults',[
|
||||||
|
'jquery',
|
||||||
'./results',
|
'./results',
|
||||||
|
|
||||||
'./selection/single',
|
'./selection/single',
|
||||||
@ -10888,6 +10933,7 @@ define('select2/defaults',[
|
|||||||
'./selection/placeholder',
|
'./selection/placeholder',
|
||||||
|
|
||||||
'./utils',
|
'./utils',
|
||||||
|
'./translation',
|
||||||
|
|
||||||
'./data/select',
|
'./data/select',
|
||||||
'./data/array',
|
'./data/array',
|
||||||
@ -10895,18 +10941,20 @@ define('select2/defaults',[
|
|||||||
'./data/tags',
|
'./data/tags',
|
||||||
|
|
||||||
'./dropdown',
|
'./dropdown',
|
||||||
'./dropdown/search'
|
'./dropdown/search',
|
||||||
], function (ResultsList,
|
|
||||||
|
'./i18n/en'
|
||||||
|
], function ($, ResultsList,
|
||||||
SingleSelection, MultipleSelection, Placeholder,
|
SingleSelection, MultipleSelection, Placeholder,
|
||||||
Utils,
|
Utils, Translation,
|
||||||
SelectData, ArrayData, AjaxData, Tags,
|
SelectData, ArrayData, AjaxData, Tags,
|
||||||
Dropdown, Search) {
|
Dropdown, Search, EnglishTranslation) {
|
||||||
function Defaults () {
|
function Defaults () {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults.prototype.apply = function (options) {
|
Defaults.prototype.apply = function (options) {
|
||||||
options = $.extend({}, options, this.defaults);
|
options = $.extend({}, this.defaults, options);
|
||||||
|
|
||||||
if (options.dataAdapter == null) {
|
if (options.dataAdapter == null) {
|
||||||
if (options.ajax) {
|
if (options.ajax) {
|
||||||
@ -10948,11 +10996,42 @@ define('select2/defaults',[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.language === 'string') {
|
||||||
|
options.language = [options.language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.isArray(options.language)) {
|
||||||
|
var languages = new Translation();
|
||||||
|
var languageNames = options.language.concat(this.defaults.language);
|
||||||
|
|
||||||
|
for (var l = 0; l < languageNames.length; l++) {
|
||||||
|
var name = languageNames[l];
|
||||||
|
var language = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to load it with the original name
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
} catch (e) {
|
||||||
|
// If we couldn't load it, check if it wasn't the full path
|
||||||
|
name = 'select2/i18n/' + name;
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
languages.extend(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.translations = languages;
|
||||||
|
} else {
|
||||||
|
options.translations = new Translations(options.language);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Defaults.prototype.reset = function () {
|
Defaults.prototype.reset = function () {
|
||||||
this.defaults = { };
|
this.defaults = {
|
||||||
|
language: ['select2/i18n/en']
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaults = new Defaults();
|
var defaults = new Defaults();
|
||||||
|
6
dist/js/select2.full.min.js
vendored
6
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
93
dist/js/select2.js
vendored
93
dist/js/select2.js
vendored
@ -1,4 +1,4 @@
|
|||||||
(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }/**
|
window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }/**
|
||||||
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
* @license almond 0.2.9 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
||||||
* Available via the MIT or new BSD license.
|
* Available via the MIT or new BSD license.
|
||||||
* see: http://github.com/jrburke/almond for details
|
* see: http://github.com/jrburke/almond for details
|
||||||
@ -1265,6 +1265,42 @@ define('select2/selection/placeholder',[
|
|||||||
return Placeholder;
|
return Placeholder;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/translation',[
|
||||||
|
|
||||||
|
], function () {
|
||||||
|
function Translation (dict) {
|
||||||
|
this.dict = dict || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Translation.prototype.all = function () {
|
||||||
|
return this.dict;
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.get = function (key) {
|
||||||
|
return this.dict[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.extend = function (translation) {
|
||||||
|
this.dict = $.extend({}, translation.all(), this.dict);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
|
||||||
|
Translation._cache = {};
|
||||||
|
|
||||||
|
Translation.loadPath = function (path) {
|
||||||
|
if (!(path in Translation._cache)) {
|
||||||
|
var translations = require(path);
|
||||||
|
|
||||||
|
Translation._cache[path] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Translation(Translation._cache[path]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Translation;
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/data/base',[
|
define('select2/data/base',[
|
||||||
'../utils'
|
'../utils'
|
||||||
], function (Utils) {
|
], function (Utils) {
|
||||||
@ -1773,7 +1809,16 @@ define('select2/dropdown/search',[
|
|||||||
return Search;
|
return Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
define('select2/i18n/en',[],function () {
|
||||||
|
return {
|
||||||
|
'no_results': function () {
|
||||||
|
return 'No results found';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
define('select2/defaults',[
|
define('select2/defaults',[
|
||||||
|
'jquery',
|
||||||
'./results',
|
'./results',
|
||||||
|
|
||||||
'./selection/single',
|
'./selection/single',
|
||||||
@ -1781,6 +1826,7 @@ define('select2/defaults',[
|
|||||||
'./selection/placeholder',
|
'./selection/placeholder',
|
||||||
|
|
||||||
'./utils',
|
'./utils',
|
||||||
|
'./translation',
|
||||||
|
|
||||||
'./data/select',
|
'./data/select',
|
||||||
'./data/array',
|
'./data/array',
|
||||||
@ -1788,18 +1834,20 @@ define('select2/defaults',[
|
|||||||
'./data/tags',
|
'./data/tags',
|
||||||
|
|
||||||
'./dropdown',
|
'./dropdown',
|
||||||
'./dropdown/search'
|
'./dropdown/search',
|
||||||
], function (ResultsList,
|
|
||||||
|
'./i18n/en'
|
||||||
|
], function ($, ResultsList,
|
||||||
SingleSelection, MultipleSelection, Placeholder,
|
SingleSelection, MultipleSelection, Placeholder,
|
||||||
Utils,
|
Utils, Translation,
|
||||||
SelectData, ArrayData, AjaxData, Tags,
|
SelectData, ArrayData, AjaxData, Tags,
|
||||||
Dropdown, Search) {
|
Dropdown, Search, EnglishTranslation) {
|
||||||
function Defaults () {
|
function Defaults () {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults.prototype.apply = function (options) {
|
Defaults.prototype.apply = function (options) {
|
||||||
options = $.extend({}, options, this.defaults);
|
options = $.extend({}, this.defaults, options);
|
||||||
|
|
||||||
if (options.dataAdapter == null) {
|
if (options.dataAdapter == null) {
|
||||||
if (options.ajax) {
|
if (options.ajax) {
|
||||||
@ -1841,11 +1889,42 @@ define('select2/defaults',[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.language === 'string') {
|
||||||
|
options.language = [options.language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.isArray(options.language)) {
|
||||||
|
var languages = new Translation();
|
||||||
|
var languageNames = options.language.concat(this.defaults.language);
|
||||||
|
|
||||||
|
for (var l = 0; l < languageNames.length; l++) {
|
||||||
|
var name = languageNames[l];
|
||||||
|
var language = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to load it with the original name
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
} catch (e) {
|
||||||
|
// If we couldn't load it, check if it wasn't the full path
|
||||||
|
name = 'select2/i18n/' + name;
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
languages.extend(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.translations = languages;
|
||||||
|
} else {
|
||||||
|
options.translations = new Translations(options.language);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Defaults.prototype.reset = function () {
|
Defaults.prototype.reset = function () {
|
||||||
this.defaults = { };
|
this.defaults = {
|
||||||
|
language: ['select2/i18n/en']
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaults = new Defaults();
|
var defaults = new Defaults();
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
@ -257,7 +257,7 @@ $(".js-programmatic-close").on("click", function () { $example.select2("close");
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="tagss" class="row">
|
<section id="tags" class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<h1>Tagging support</h1>
|
<h1>Tagging support</h1>
|
||||||
|
|
||||||
@ -288,6 +288,40 @@ $(".js-programmatic-close").on("click", function () { $example.select2("close");
|
|||||||
$(".js-example-tags").select2({
|
$(".js-example-tags").select2({
|
||||||
tags: true
|
tags: true
|
||||||
})
|
})
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="language" class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h1>Multiple languages</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Select2 supports displaying the messages in different languages, as well
|
||||||
|
as provding your own custom messages that can be displayed.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<select class="js-example-language js-states form-control">
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Note that when tagging is enabled the user can select from pre-existing
|
||||||
|
options or create a new tag by picking the first choice, which is what
|
||||||
|
the user has typed into the search box so far.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<h2>Example code</h2>
|
||||||
|
|
||||||
|
<pre data-fill-from=".js-code-language"></pre>
|
||||||
|
|
||||||
|
<script type="text/x-example-code" class="js-code-language">
|
||||||
|
$(".js-example-language").select2({
|
||||||
|
language: "es"
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@ -388,6 +422,8 @@ $.fn.select2.amd.require(["select2/core", "select2/utils"], function (Select2, U
|
|||||||
|
|
||||||
var $tags = $(".js-example-tags");
|
var $tags = $(".js-example-tags");
|
||||||
|
|
||||||
|
var $language = $(".js-example-language");
|
||||||
|
|
||||||
$basicSingle.select2();
|
$basicSingle.select2();
|
||||||
$basicMultiple.select2()
|
$basicMultiple.select2()
|
||||||
|
|
||||||
@ -414,5 +450,9 @@ $.fn.select2.amd.require(["select2/core", "select2/utils"], function (Select2, U
|
|||||||
$tags.select2({
|
$tags.select2({
|
||||||
tags: true
|
tags: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$language.select2({
|
||||||
|
language: "en"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"start": "(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }",
|
"start": "window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.select2.amd) { define = $.fn.select2.amd.define; require = $.fn.select2.amd.require; }",
|
||||||
"end": "require('jquery.select2'); $.fn.select2.amd = { define: define, require: require };}());"
|
"end": "require('jquery.select2'); $.fn.select2.amd = { define: define, require: require };}());"
|
||||||
}
|
}
|
||||||
|
47
src/js/select2/defaults.js
vendored
47
src/js/select2/defaults.js
vendored
@ -1,4 +1,5 @@
|
|||||||
define([
|
define([
|
||||||
|
'jquery',
|
||||||
'./results',
|
'./results',
|
||||||
|
|
||||||
'./selection/single',
|
'./selection/single',
|
||||||
@ -6,6 +7,7 @@ define([
|
|||||||
'./selection/placeholder',
|
'./selection/placeholder',
|
||||||
|
|
||||||
'./utils',
|
'./utils',
|
||||||
|
'./translation',
|
||||||
|
|
||||||
'./data/select',
|
'./data/select',
|
||||||
'./data/array',
|
'./data/array',
|
||||||
@ -13,18 +15,20 @@ define([
|
|||||||
'./data/tags',
|
'./data/tags',
|
||||||
|
|
||||||
'./dropdown',
|
'./dropdown',
|
||||||
'./dropdown/search'
|
'./dropdown/search',
|
||||||
], function (ResultsList,
|
|
||||||
|
'./i18n/en'
|
||||||
|
], function ($, ResultsList,
|
||||||
SingleSelection, MultipleSelection, Placeholder,
|
SingleSelection, MultipleSelection, Placeholder,
|
||||||
Utils,
|
Utils, Translation,
|
||||||
SelectData, ArrayData, AjaxData, Tags,
|
SelectData, ArrayData, AjaxData, Tags,
|
||||||
Dropdown, Search) {
|
Dropdown, Search, EnglishTranslation) {
|
||||||
function Defaults () {
|
function Defaults () {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults.prototype.apply = function (options) {
|
Defaults.prototype.apply = function (options) {
|
||||||
options = $.extend({}, options, this.defaults);
|
options = $.extend({}, this.defaults, options);
|
||||||
|
|
||||||
if (options.dataAdapter == null) {
|
if (options.dataAdapter == null) {
|
||||||
if (options.ajax) {
|
if (options.ajax) {
|
||||||
@ -66,11 +70,42 @@ define([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.language === 'string') {
|
||||||
|
options.language = [options.language];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.isArray(options.language)) {
|
||||||
|
var languages = new Translation();
|
||||||
|
var languageNames = options.language.concat(this.defaults.language);
|
||||||
|
|
||||||
|
for (var l = 0; l < languageNames.length; l++) {
|
||||||
|
var name = languageNames[l];
|
||||||
|
var language = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to load it with the original name
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
} catch (e) {
|
||||||
|
// If we couldn't load it, check if it wasn't the full path
|
||||||
|
name = 'select2/i18n/' + name;
|
||||||
|
language = Translation.loadPath(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
languages.extend(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
options.translations = languages;
|
||||||
|
} else {
|
||||||
|
options.translations = new Translations(options.language);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Defaults.prototype.reset = function () {
|
Defaults.prototype.reset = function () {
|
||||||
this.defaults = { };
|
this.defaults = {
|
||||||
|
language: ['select2/i18n/en']
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaults = new Defaults();
|
var defaults = new Defaults();
|
||||||
|
35
src/js/select2/translation.js
vendored
Normal file
35
src/js/select2/translation.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
define([
|
||||||
|
|
||||||
|
], function () {
|
||||||
|
function Translation (dict) {
|
||||||
|
this.dict = dict || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Translation.prototype.all = function () {
|
||||||
|
return this.dict;
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.get = function (key) {
|
||||||
|
return this.dict[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
Translation.prototype.extend = function (translation) {
|
||||||
|
this.dict = $.extend({}, translation.all(), this.dict);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Static functions
|
||||||
|
|
||||||
|
Translation._cache = {};
|
||||||
|
|
||||||
|
Translation.loadPath = function (path) {
|
||||||
|
if (!(path in Translation._cache)) {
|
||||||
|
var translations = require(path);
|
||||||
|
|
||||||
|
Translation._cache[path] = translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Translation(Translation._cache[path]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Translation;
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user