-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.gs
89 lines (70 loc) · 2.58 KB
/
main.gs
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
82
83
84
85
86
87
88
// avoid naming the sheet with "i18n-", "i18n-{OS}" is the exported scripts for the corresponding OS.
// the program will take the number of language from first spreadsheet as the reference.
// iOS
function exportToIOS() {
exportToMobileScript(IOS_obj);
}
//Android
function exportToAOS() {
exportToMobileScript(AOS_obj);
}
function exportToMobileScript(obj){
var spreadsheet = SpreadsheetApp.getActive()
var total = spreadsheet.getSheets().length
var sheetName = obj.sheetName // exported sheet name
// get number of language.
var numOfLang = 0
for (var i=0; i<total; i++){
if (!spreadsheet.getSheets()[i].getSheetName().includes("i18n-")){
numOfLang = spreadsheet.getSheets()[i].getLastColumn() - 1
break
}
}
if (numOfLang < 1){
Logger.log("[ERROR] cannot determine number of language: The 1st spreadsheet contains only " + numOfLang + " row.")
return
}else{
Logger.log("# of language = " + numOfLang)
}
var langData = new Array()
for (var a=0; a<total; a++)
{
var sheet = spreadsheet.getSheets()[a]
if (sheet.getSheetName().includes("i18n-")) continue
langData[langData.length] = new Array(numOfLang)
var idRange = 'A2:' + columnToLetter(sheet.getLastColumn()) + sheet.getLastRow().toString()
Logger.log("[" + sheet.getSheetName() + "]->[" + idRange + "]")
langData.push(addCustom(obj.commentHeader, numOfLang))
langData.push(addCustom("* " + sheet.getSheetName(), numOfLang))
langData.push(addCustom(obj.commentFooter, numOfLang))
langData.push(addCustom("", numOfLang))
sheet.getRange(idRange)
.getValues()
.forEach(function(col, i) {
var rowData = new Array()
for (var j=1; j<=numOfLang; j++){
if (col[0] == ""){ // column 0 is empty
rowData.push("")
}else if (col[j] == ""){ // column 0 has value, but column 1 is empty
// rowData.push("// " + col[0])
rowData.push(obj.oneLineComment(col[0]))
}else{ // at least has 1 key-pair
// rowData.push('"' + col[0] + '" = ' + '"' + col[j] + '";')
rowData.push(obj.keyPairCode(col[0], col[j]))
}
}
langData.push(rowData)
})
// print to spreadsheet
var i18nSheet = spreadsheet.getSheetByName(sheetName)
if (i18nSheet == null){
spreadsheet.insertSheet(sheetName)
i18nSheet = spreadsheet.getSheetByName(sheetName)
}else
i18nSheet.clearContents()
for (var i=0; i<langData.length; i++) {
i18nSheet.getRange(1,1,langData.length, langData[i].length)
.setValues(langData)
}
}
}