浏览代码

Added Spanish translation and fixed the example

Kevin Brown 10 年之前
父节点
当前提交
c7e8f81595

+ 2 - 1
Gruntfile.js

@@ -9,7 +9,8 @@ module.exports = function (grunt) {
   ];
 
   fullIncludes = [
-    'jquery'
+    'jquery',
+    'select2/compat/matcher'
   ].concat(includes);
 
   var i18nModules = [];

+ 1 - 0
dist/js/i18n/es.js

@@ -0,0 +1 @@
+window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/es",[],function(){return{inputTooShort:function(e){var t="Por favor, introduzca "+remainingChars+" car";return remainingChars==1?t+="ácter":t+="acteres",t},loadingMore:function(){return"Cargando más resultados…"},noResults:function(){return"No se encontraron resultados"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}}();

+ 44 - 45
dist/js/select2.amd.full.js

@@ -1636,49 +1636,6 @@ define('select2/i18n/en',[],function () {
   };
 });
 
-define('select2/compat/matcher',[
-
-], function () {
-  function oldMatcher (matcher) {
-    function wrappedMatcher (params, data) {
-      var match = $.extend(true, {}, data);
-
-      if (params.term == null || $.trim(params.term) === '') {
-        return match;
-      }
-
-      if (data.children) {
-        for (var c = data.children.length - 1; c >= 0; c--) {
-          var child = data.children[c];
-
-          // Check if the child object matches
-          // The old matcher returned a boolean true or false
-          var doesMatch = matcher(params.term, child.text, child);
-
-          // If the child didn't match, pop it off
-          if (!doesMatch) {
-            match.children.splice(c, 1);
-          }
-        }
-
-        if (match.children.length > 0) {
-          return match;
-        }
-      }
-
-      if (matcher(params.term, data.text, data)) {
-        return match;
-      }
-
-      return null;
-    }
-
-    return wrappedMatcher;
-  }
-
-  return oldMatcher;
-});
-
 define('select2/defaults',[
   'jquery',
   './results',
@@ -1701,8 +1658,7 @@ define('select2/defaults',[
   './dropdown/hidePlaceholder',
   './dropdown/infiniteScroll',
 
-  './i18n/en',
-  './compat/matcher'
+  './i18n/en'
 ], function ($, ResultsList,
              SingleSelection, MultipleSelection, Placeholder,
              Utils, Translation,
@@ -2218,6 +2174,49 @@ define('select2/core',[
   return Select2;
 });
 
+define('select2/compat/matcher',[
+
+], function () {
+  function oldMatcher (matcher) {
+    function wrappedMatcher (params, data) {
+      var match = $.extend(true, {}, data);
+
+      if (params.term == null || $.trim(params.term) === '') {
+        return match;
+      }
+
+      if (data.children) {
+        for (var c = data.children.length - 1; c >= 0; c--) {
+          var child = data.children[c];
+
+          // Check if the child object matches
+          // The old matcher returned a boolean true or false
+          var doesMatch = matcher(params.term, child.text, child);
+
+          // If the child didn't match, pop it off
+          if (!doesMatch) {
+            match.children.splice(c, 1);
+          }
+        }
+
+        if (match.children.length > 0) {
+          return match;
+        }
+      }
+
+      if (matcher(params.term, data.text, data)) {
+        return match;
+      }
+
+      return null;
+    }
+
+    return wrappedMatcher;
+  }
+
+  return oldMatcher;
+});
+
 define('jquery.select2',[
   'jquery',
   'select2/core'

+ 1 - 45
dist/js/select2.amd.js

@@ -1636,49 +1636,6 @@ define('select2/i18n/en',[],function () {
   };
 });
 
-define('select2/compat/matcher',[
-
-], function () {
-  function oldMatcher (matcher) {
-    function wrappedMatcher (params, data) {
-      var match = $.extend(true, {}, data);
-
-      if (params.term == null || $.trim(params.term) === '') {
-        return match;
-      }
-
-      if (data.children) {
-        for (var c = data.children.length - 1; c >= 0; c--) {
-          var child = data.children[c];
-
-          // Check if the child object matches
-          // The old matcher returned a boolean true or false
-          var doesMatch = matcher(params.term, child.text, child);
-
-          // If the child didn't match, pop it off
-          if (!doesMatch) {
-            match.children.splice(c, 1);
-          }
-        }
-
-        if (match.children.length > 0) {
-          return match;
-        }
-      }
-
-      if (matcher(params.term, data.text, data)) {
-        return match;
-      }
-
-      return null;
-    }
-
-    return wrappedMatcher;
-  }
-
-  return oldMatcher;
-});
-
 define('select2/defaults',[
   'jquery',
   './results',
@@ -1701,8 +1658,7 @@ define('select2/defaults',[
   './dropdown/hidePlaceholder',
   './dropdown/infiniteScroll',
 
-  './i18n/en',
-  './compat/matcher'
+  './i18n/en'
 ], function ($, ResultsList,
              SingleSelection, MultipleSelection, Placeholder,
              Utils, Translation,

+ 44 - 45
dist/js/select2.full.js

@@ -11171,49 +11171,6 @@ define('select2/i18n/en',[],function () {
   };
 });
 
-define('select2/compat/matcher',[
-
-], function () {
-  function oldMatcher (matcher) {
-    function wrappedMatcher (params, data) {
-      var match = $.extend(true, {}, data);
-
-      if (params.term == null || $.trim(params.term) === '') {
-        return match;
-      }
-
-      if (data.children) {
-        for (var c = data.children.length - 1; c >= 0; c--) {
-          var child = data.children[c];
-
-          // Check if the child object matches
-          // The old matcher returned a boolean true or false
-          var doesMatch = matcher(params.term, child.text, child);
-
-          // If the child didn't match, pop it off
-          if (!doesMatch) {
-            match.children.splice(c, 1);
-          }
-        }
-
-        if (match.children.length > 0) {
-          return match;
-        }
-      }
-
-      if (matcher(params.term, data.text, data)) {
-        return match;
-      }
-
-      return null;
-    }
-
-    return wrappedMatcher;
-  }
-
-  return oldMatcher;
-});
-
 define('select2/defaults',[
   'jquery',
   './results',
@@ -11236,8 +11193,7 @@ define('select2/defaults',[
   './dropdown/hidePlaceholder',
   './dropdown/infiniteScroll',
 
-  './i18n/en',
-  './compat/matcher'
+  './i18n/en'
 ], function ($, ResultsList,
              SingleSelection, MultipleSelection, Placeholder,
              Utils, Translation,
@@ -11753,6 +11709,49 @@ define('select2/core',[
   return Select2;
 });
 
+define('select2/compat/matcher',[
+
+], function () {
+  function oldMatcher (matcher) {
+    function wrappedMatcher (params, data) {
+      var match = $.extend(true, {}, data);
+
+      if (params.term == null || $.trim(params.term) === '') {
+        return match;
+      }
+
+      if (data.children) {
+        for (var c = data.children.length - 1; c >= 0; c--) {
+          var child = data.children[c];
+
+          // Check if the child object matches
+          // The old matcher returned a boolean true or false
+          var doesMatch = matcher(params.term, child.text, child);
+
+          // If the child didn't match, pop it off
+          if (!doesMatch) {
+            match.children.splice(c, 1);
+          }
+        }
+
+        if (match.children.length > 0) {
+          return match;
+        }
+      }
+
+      if (matcher(params.term, data.text, data)) {
+        return match;
+      }
+
+      return null;
+    }
+
+    return wrappedMatcher;
+  }
+
+  return oldMatcher;
+});
+
 define('jquery.select2',[
   'jquery',
   'select2/core'

文件差异内容过多而无法显示
+ 0 - 0
dist/js/select2.full.min.js


+ 1 - 45
dist/js/select2.js

@@ -2064,49 +2064,6 @@ define('select2/i18n/en',[],function () {
   };
 });
 
-define('select2/compat/matcher',[
-
-], function () {
-  function oldMatcher (matcher) {
-    function wrappedMatcher (params, data) {
-      var match = $.extend(true, {}, data);
-
-      if (params.term == null || $.trim(params.term) === '') {
-        return match;
-      }
-
-      if (data.children) {
-        for (var c = data.children.length - 1; c >= 0; c--) {
-          var child = data.children[c];
-
-          // Check if the child object matches
-          // The old matcher returned a boolean true or false
-          var doesMatch = matcher(params.term, child.text, child);
-
-          // If the child didn't match, pop it off
-          if (!doesMatch) {
-            match.children.splice(c, 1);
-          }
-        }
-
-        if (match.children.length > 0) {
-          return match;
-        }
-      }
-
-      if (matcher(params.term, data.text, data)) {
-        return match;
-      }
-
-      return null;
-    }
-
-    return wrappedMatcher;
-  }
-
-  return oldMatcher;
-});
-
 define('select2/defaults',[
   'jquery',
   './results',
@@ -2129,8 +2086,7 @@ define('select2/defaults',[
   './dropdown/hidePlaceholder',
   './dropdown/infiniteScroll',
 
-  './i18n/en',
-  './compat/matcher'
+  './i18n/en'
 ], function ($, ResultsList,
              SingleSelection, MultipleSelection, Placeholder,
              Utils, Translation,

文件差异内容过多而无法显示
+ 0 - 0
dist/js/select2.min.js


+ 9 - 6
docs/examples.html

@@ -4,6 +4,8 @@ title: Examples - Select2
 slug: examples
 ---
 
+<script type="text/javascript" src="dist/js/i18n/es.js"></script>
+
 <div class="container">
   <section id="basic" class="row">
     <div class="col-md-4">
@@ -343,7 +345,9 @@ $.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
 
       <p>
         Select2 supports displaying the messages in different languages, as well
-        as provding your own custom messages that can be displayed.
+        as provding your own
+        <a href="options.html#language">custom messages</a>
+        that can be displayed.
       </p>
 
       <p>
@@ -352,11 +356,10 @@ $.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
       </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.
+        The language does not have to be defined when Select2 is being
+        initialized, but instead can be defined in the <code>[lang]</code>
+        attribute of any parent elements as <code>[lang="es"]</code>.
       </p>
-
     </div>
     <div class="col-md-8">
       <h2>Example code</h2>
@@ -565,7 +568,7 @@ $.fn.select2.amd.require(
   });
 
   $language.select2({
-    language: "en"
+    language: "es"
   });
 });
 </script>

+ 1 - 2
src/js/select2/defaults.js

@@ -20,8 +20,7 @@ define([
   './dropdown/hidePlaceholder',
   './dropdown/infiniteScroll',
 
-  './i18n/en',
-  './compat/matcher'
+  './i18n/en'
 ], function ($, ResultsList,
              SingleSelection, MultipleSelection, Placeholder,
              Utils, Translation,

+ 21 - 0
src/js/select2/i18n/es.js

@@ -0,0 +1,21 @@
+define(function () {
+  return {
+    inputTooShort: function (args) {
+      var message = 'Por favor, introduzca ' + remainingChars + ' car';
+
+      if (remainingChars == 1) {
+        message += 'ácter';
+      } else {
+        message += 'acteres';
+      }
+
+      return message;
+    },
+    loadingMore: function () {
+      return 'Cargando más resultados…';
+    },
+    noResults: function () {
+      return 'No se encontraron resultados';
+    }
+  };
+});

部分文件因为文件数量过多而无法显示