2017-08-31 11:27:57 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
from pprint import pprint
|
2017-08-31 11:27:57 +02:00
|
|
|
import csv
|
2017-09-10 21:11:48 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import xlrd
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
if len(sys.argv) == 1:
|
|
|
|
print('Usage: {} input.(csv|xls)'.format(sys.argv[0]))
|
|
|
|
sys.exit(1)
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
basename, extension = os.path.splitext(sys.argv[1].lower())
|
|
|
|
translations = {}
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
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)
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
with open('{}.py'.format(basename), 'wb') as langfile:
|
|
|
|
pprint(translations, langfile)
|