From 20fcaa444975e7561573047615f4851ded240213 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Fri, 31 Oct 2014 22:17:21 -0400 Subject: [PATCH] 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. --- .gitignore | 1 + Gruntfile.js | 27 +++++++++++++++++++++++++++ dist/js/i18n/en.js | 1 + src/js/select2/i18n/en.js | 7 +++++++ 4 files changed, 36 insertions(+) create mode 100644 dist/js/i18n/en.js create mode 100644 src/js/select2/i18n/en.js diff --git a/.gitignore b/.gitignore index 3c3629e6..163c732b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +dist/js/i18n/build.txt diff --git a/Gruntfile.js b/Gruntfile.js index b47d6d57..6782576f 100644 --- a/Gruntfile.js +++ b/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') + } } }, diff --git a/dist/js/i18n/en.js b/dist/js/i18n/en.js new file mode 100644 index 00000000..0250e6c9 --- /dev/null +++ b/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}})(); \ No newline at end of file diff --git a/src/js/select2/i18n/en.js b/src/js/select2/i18n/en.js new file mode 100644 index 00000000..3fbfe9df --- /dev/null +++ b/src/js/select2/i18n/en.js @@ -0,0 +1,7 @@ +define(function () { + return { + 'no_results': function () { + return 'No results found'; + } + }; +});