-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateCSV.py
More file actions
59 lines (46 loc) · 1.74 KB
/
createCSV.py
File metadata and controls
59 lines (46 loc) · 1.74 KB
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
import csv
import codecs
import os
import re
import itertools
def generateLanguages(language_codes, writer, tempRow, counter):
letters = []
for each in itertools.chain(*[itertools.product(map(chr, range(65,91)), repeat=i) for i in range(1, 5)]):
letters.append(each);
letters.pop(0);
letters.pop(0);
for i in range(len(language_codes) - 2):
tempRow.append('=GOOGLETRANSLATE($B%s, B1, $%s$1)' %(counter, ''.join(letters[i])));
writer.writerow(tempRow);
def main():
print("Enter the XML filename with the extension")
print("example: strings.xml ")
inputFile = input();
language_codes = ["", "en"]
languageCodesFile = open("language_codes.txt","r");
for line in languageCodesFile.readlines():
language_codes.append(line.strip());
languageCodesFile.close();
#Make the root directory for the strings
if not os.path.exists("translationsOutput"):
os.makedirs("translationsOutput");
#Open the XML file and create the writer from the file
with codecs.open(inputFile, encoding="utf-8") as file:
with codecs.open("translationsOutput/generatedCSV.csv", 'wb', encoding="utf-8") as outputFile:
writer = csv.writer(outputFile);
writer.writerow(language_codes);
lines = file.readlines();
counter = 1;
for line in lines:
tempRow = []
stringName = re.search(r'"([^"]*)"', line);
if(stringName != None):
tempRow.append(stringName.group()[1:-1])
stringText = re.search(r'>([^"]*)</', line);
if(stringText != None):
tempRow.append(stringText.group()[1:-2]);
generateLanguages(language_codes, writer, tempRow, counter);
counter += 1;
print("Done - Created generatedCSV.csv")
print("Find the file in the translationsOutput folder")
main();