-
Notifications
You must be signed in to change notification settings - Fork 16
/
localization.js
68 lines (67 loc) · 2.03 KB
/
localization.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var showdown = require('showdown'),
converter = new showdown.Converter();
module.exports = function(grunt) {
return {
options: {
tpl:{
index: 'src/tpl/index.html',
offline: 'src/tpl/index.html',
readme: 'src/tpl/readme.md',
welcome: 'src/tpl/readme.md',
about: 'src/tpl/about.md'
},
renderer: function(k, v) {
var ctx = this.ctx,
arr = /^@.+\.(\w{2,4})$/i.exec(k);
if(!!arr) {
var ret = /_(\w{2}\-\w{2})\.\w{2,4}/i.exec(ctx.dest),lang='en-US',
filename=k.substring(1),
defPath='src/lang/'+lang+'/'+filename;
if(!!ret) {
lang = ret[1];
}
var path = 'src/lang/'+lang+'/'+filename,
mdString=null;
console.log(path);
if(grunt.file.exists(path)) {
mdString = grunt.file.read(path);
} else {
mdString = grunt.file.read(defPath);
}
v = arr[1].toLowerCase()==='md'?converter.makeHtml(mdString):mdString;
}
return v;
}
},
index: {
files: {
'index.html': ['src/lang/en-US/main.json'],
'index_zh-CN.html': ['src/lang/en-US/main.json','src/lang/zh-CN/main.json']
}
},
offline: {
files: {
'dist/index.html': ['src/lang/en-US/main.json','src/lang/en-US/offline.json'],
'dist/index_zh-CN.html': ['src/lang/en-US/main.json','src/lang/zh-CN/main.json','src/lang/en-US/offline.json','src/lang/zh-CN/offline.json']
}
},
readme: {
files: {
'README.md': ['src/lang/en-US/main.json','src/lang/en-US/readme.json'],
'README_zh-CN.md': ['src/lang/zh-CN/main.json','src/lang/zh-CN/readme.json']
}
},
welcome: {
files: {
'dist/WELCOME.md': ['src/lang/en-US/welcome.json'],
'dist/WELCOME_zh-CN.md': ['src/lang/zh-CN/welcome.json']
}
},
about: {
files: {
'dist/ABOUT.md': ['src/lang/en-US/main.json','src/lang/en-US/offline.json'],
'dist/ABOUT_zh-CN.md': ['src/lang/en-US/main.json','src/lang/zh-CN/main.json','src/lang/zh-CN/offline.json']
}
}
};
};