forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_txt_from_csv.py
41 lines (31 loc) · 1.19 KB
/
strings_txt_from_csv.py
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
from __future__ import print_function
import csv
from collections import defaultdict
import sys
if len(sys.argv) <= 1:
print("""
* * *
This script turns a csv file resulting from "translated strings" in the google sheet file into a strings.txt-formated file.
To use this script, create the translated strings using the google spread-sheet. Go to file -> Download as, and choose csv. Only the currently open sheet will be exported.
Run this script with the path to the downloaded file as a parameter. The formatted file will be printed to the console.
Please note, that the order of keys is not (yet) preserved.
* * *
""")
exit(2)
path = sys.argv[1]
resulting_dict = defaultdict(list)
with open(path, mode='r') as infile:
reader = csv.reader(infile)
column_names = next(reader)
for strings in reader:
for i, string in enumerate(strings):
if string:
resulting_dict[column_names[i]].append(string)
for key in column_names:
if not key:
continue
translations = resulting_dict[key]
print(" {}".format(key))
for translation in translations:
print(" {}".format(translation))
print("")