-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathtranslate.js
52 lines (44 loc) · 1.87 KB
/
translate.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
module.exports = function(grunt) {
const Helpers = require('../helpers')(grunt);
grunt.registerTask('translate', 'Import/export for translations. For more details, please visit https://github.com/adaptlearning/adapt_framework/wiki/Course-Localisation', function(mode) {
const next = this.async();
const framework = Helpers.getFramework();
grunt.log.ok(`Using ${framework.useOutputData ? framework.outputPath : framework.sourcePath} folder for course data...`);
const translate = framework.getTranslate({
masterLang: grunt.option('masterLang') || 'en',
targetLang: grunt.option('targetLang') || null,
format: grunt.option('format') || 'csv',
csvDelimiter: grunt.option('csvDelimiter') || ',',
shouldReplaceExisting: grunt.option('replace') || false,
languagePath: grunt.option('languagedir') || 'languagefiles',
isTest: grunt.option('test') || false,
log: grunt.log.ok
});
switch (mode) {
case 'export':
translate.export().then(next, err => {
grunt.log.error(err);
next();
});
break;
case 'import':
translate.import().then(next, err => {
switch (err.number) {
case 10001: // Target language option is missing
grunt.log.error(err + `\nPlease add --targetLang=<languageCode>`);
break;
case 10002: // Import source folder does not exist.
grunt.log.error(err + `\nPlease create this folder in the languagefiles directory.`);
break;
case 10003: // Import destination folder already exists.
grunt.log.error(err + `\nTo replace the content in this folder, please add a --replace flag to the grunt task.`);
break;
default:
grunt.log.error(err);
}
next();
});
break;
}
});
};