Parcourir la source

Start working on translations

This adds a custom r.js build for i18n, which processes each JS
file in the `select2/i18n` directory and builds it.

So far only the "No results found" translation has been added.
Kevin Brown il y a 10 ans
Parent
commit
20fcaa4449
4 fichiers modifiés avec 36 ajouts et 0 suppressions
  1. 1 0
      .gitignore
  2. 27 0
      Gruntfile.js
  3. 1 0
      dist/js/i18n/en.js
  4. 7 0
      src/js/select2/i18n/en.js

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 node_modules
+dist/js/i18n/build.txt

+ 27 - 0
Gruntfile.js

@@ -12,6 +12,24 @@ module.exports = function (grunt) {
     'jquery'
   ].concat(includes);
 
+  var i18nModules = [];
+  var i18nPaths = {};
+
+  var i18nFiles = grunt.file.expand({
+    cwd: 'src/js'
+  }, 'select2/i18n/*.js');
+
+  for (var i = 0; i < i18nFiles.length; i++) {
+    var file = i18nFiles[i];
+    var name = file.split('.')[0];
+
+    i18nModules.push({
+      name: name
+    });
+
+    i18nPaths[name] = '../../' + name;
+  }
+
   grunt.initConfig({
     uglify: {
       'dist': {
@@ -121,6 +139,15 @@ module.exports = function (grunt) {
           },
           wrap: grunt.file.readJSON('src/js/banner.json')
         }
+      },
+      'i18n': {
+        options: {
+          baseUrl: 'src/js/select2/i18n',
+          dir: 'dist/js/i18n',
+          paths: i18nPaths,
+          modules: i18nModules,
+          wrap: grunt.file.readJSON('src/js/banner.json')
+        }
       }
     },
 

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

@@ -0,0 +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}})();

+ 7 - 0
src/js/select2/i18n/en.js

@@ -0,0 +1,7 @@
+define(function () {
+  return {
+    'no_results': function () {
+      return 'No results found';
+    }
+  };
+});