Update sahana-lang-csv.py to support both csv and xls.
This commit is contained in:
parent
7d45652126
commit
2d1b7eaecb
@ -1,26 +1,32 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import csv
|
from __future__ import print_function
|
||||||
|
|
||||||
dictionary = {}
|
|
||||||
with open('cz.csv', 'rb') as csvfile:
|
|
||||||
reader = csv.reader(csvfile, delimiter=',', quotechar='\'')
|
|
||||||
for line in reader:
|
|
||||||
dictionary[line[1]] = line[2]
|
|
||||||
|
|
||||||
with open('cz.py', 'wb') as langfile:
|
|
||||||
langfile.write(str(dictionary))
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
import xlrd
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import xlrd
|
||||||
|
|
||||||
dictionary = {}
|
if len(sys.argv) == 1:
|
||||||
sheet = xlrd.open_workbook('cz.xls').sheet_by_index(0)
|
print('Usage: {} input.(csv|xls)'.format(sys.argv[0]))
|
||||||
for i in range(1, sheet.nrows):
|
sys.exit(1)
|
||||||
row = sheet.row(i)
|
|
||||||
dictionary[row[1].value.encode('utf-8')] = row[2].value.encode('utf-8')
|
|
||||||
|
|
||||||
with open('cz.py', 'wb') as langfile:
|
basename, extension = os.path.splitext(sys.argv[1].lower())
|
||||||
pprint(dictionary, langfile)
|
translations = {}
|
||||||
|
|
||||||
|
if extension == '.csv':
|
||||||
|
with open(sys.argv[0], 'rb') as csvfile:
|
||||||
|
reader = csv.reader(csvfile, delimiter=',', quotechar='\'')
|
||||||
|
for line in reader:
|
||||||
|
translations[line[1].encode('utf-8')] = line[2].encode('utf-8')
|
||||||
|
elif extension == '.xls':
|
||||||
|
sheet = xlrd.open_workbook(sys.argv[0]).sheet_by_index(0)
|
||||||
|
for i in range(1, sheet.nrows):
|
||||||
|
row = sheet.row(i)
|
||||||
|
translations[row[1].value.encode('utf-8')] = row[2].value.encode('utf-8')
|
||||||
|
else:
|
||||||
|
print('Unknown input file extension')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
with open('{}.py'.format(basename), 'wb') as langfile:
|
||||||
|
pprint(translations, langfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user