-
Notifications
You must be signed in to change notification settings - Fork 0
/
pseudoTranslate.js
executable file
·81 lines (61 loc) · 2.03 KB
/
pseudoTranslate.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
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* This is used to perform pseduo translation
*/
var fs = require( 'fs' ),
path = require( 'path' );
//List of languages to translate and their prefixes
var languages = {
'en': '',
'en-US': '',
'de': 'deößü',
'es': 'és',
'fr': 'frê',
'it': 'ìt',
'ja': 'かきま',
'ko': '안올외',
'ru': 'шдь',
'pt-br': 'pt-àí',
'zh-cn': '术语表',
'zh-tw': '術語'
};
function translateObject( messageJson, prefix ) {
for( var key in messageJson ) {
if( messageJson.hasOwnProperty( key ) ) {
if( typeof messageJson[key] === 'object' ) {
translateObject( messageJson[key], prefix );
} else {
messageJson[key] = prefix + messageJson[key];
}
}
}
}
function createTranslatedFile( messageJson, language, pathToDestLangs ) {
//Get the character set to append
var prefix = languages[language];
//Translate the JSON
translateObject( messageJson, prefix );
//JSON the translated file
var translatedMessageJson = JSON.stringify( messageJson, null, 4 );
// write-out the json text
destinationFile = pathToDestLangs + '/lang_' + language + '.js';
fs.writeFile( destinationFile, translatedMessageJson, function( err ) {
if( err ) {
console.log( err );
}
} );
}
function pseudoTranslate( messageFile, pathToDestLangs ) {
fs.readFile( messageFile, 'utf8', function( err, data ) {
if( err ) {
console.log( 'Error: ' + err );
return;
}
//Loop through the supported languages and create the translation file
for( var supportedLanguage in languages ) {
var messageJsonObject = JSON.parse( data );
createTranslatedFile( messageJsonObject, supportedLanguage, pathToDestLangs );
}
} );
}
// prefix of generated filename (with e.g. "_en-us.js" appended)
pseudoTranslate('src/messages/lang-en.js', 'src/messages/');