Skip to content

Commit 20fcaa4

Browse files
committed
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.
1 parent 65875bf commit 20fcaa4

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
dist/js/i18n/build.txt

Gruntfile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ module.exports = function (grunt) {
1212
'jquery'
1313
].concat(includes);
1414

15+
var i18nModules = [];
16+
var i18nPaths = {};
17+
18+
var i18nFiles = grunt.file.expand({
19+
cwd: 'src/js'
20+
}, 'select2/i18n/*.js');
21+
22+
for (var i = 0; i < i18nFiles.length; i++) {
23+
var file = i18nFiles[i];
24+
var name = file.split('.')[0];
25+
26+
i18nModules.push({
27+
name: name
28+
});
29+
30+
i18nPaths[name] = '../../' + name;
31+
}
32+
1533
grunt.initConfig({
1634
uglify: {
1735
'dist': {
@@ -121,6 +139,15 @@ module.exports = function (grunt) {
121139
},
122140
wrap: grunt.file.readJSON('src/js/banner.json')
123141
}
142+
},
143+
'i18n': {
144+
options: {
145+
baseUrl: 'src/js/select2/i18n',
146+
dir: 'dist/js/i18n',
147+
paths: i18nPaths,
148+
modules: i18nModules,
149+
wrap: grunt.file.readJSON('src/js/banner.json')
150+
}
124151
}
125152
},
126153

dist/js/i18n/en.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/i18n/en.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define(function () {
2+
return {
3+
'no_results': function () {
4+
return 'No results found';
5+
}
6+
};
7+
});

0 commit comments

Comments
 (0)