2017-09-16 18:52:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-10 21:11:48 +02:00
|
|
|
from pprint import pprint
|
2017-09-16 18:52:16 +02:00
|
|
|
import argparse
|
2017-08-31 11:27:57 +02:00
|
|
|
import csv
|
2017-09-10 21:11:48 +02:00
|
|
|
import os
|
|
|
|
import xlrd
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-16 18:52:16 +02:00
|
|
|
def main(args):
|
|
|
|
translations = {}
|
|
|
|
basename, extension = os.path.splitext(args.inputfile.lower())
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-16 18:52:16 +02:00
|
|
|
if extension == '.csv':
|
|
|
|
with open(args.inputfile, 'r') as csvfile:
|
|
|
|
reader = csv.reader(csvfile, delimiter=',', quotechar='\'')
|
|
|
|
for line in reader:
|
|
|
|
translations[line[1]] = line[2]
|
2020-04-16 23:08:06 +02:00
|
|
|
elif extension in ('.xls', '.xlsx'):
|
2017-09-16 18:52:16 +02:00
|
|
|
sheet = xlrd.open_workbook(args.inputfile).sheet_by_index(0)
|
|
|
|
for i in range(1, sheet.nrows):
|
|
|
|
row = sheet.row(i)
|
|
|
|
translations[row[1].value] = row[2].value
|
|
|
|
else:
|
|
|
|
print('Unknown input file extension')
|
|
|
|
return
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-16 18:52:16 +02:00
|
|
|
with open('{}.py'.format(basename), 'w') as langfile:
|
|
|
|
print('# -*- coding: utf-8 -*-', file=langfile)
|
|
|
|
pprint(translations, langfile, 0, 8192)
|
2017-08-31 11:27:57 +02:00
|
|
|
|
2017-09-16 18:52:16 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Spotter Cluster Sahana Eden translation converter')
|
|
|
|
parser.add_argument('inputfile', help='CSV or XLS translation file.')
|
|
|
|
main(parser.parse_args())
|