-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_po.py
39 lines (30 loc) · 947 Bytes
/
create_po.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
import os
import sys
import pandas as pd
# #####
# Creates or updates a PO file with new/modified strings for WP Menus
# #####
if len(sys.argv) == 1:
print('No post type specified... Exiting.')
sys.exit()
file = sys.argv[1]
file_prefix = file.replace("_template", "")
df = pd.read_excel(file+".xlsx", None)
sheets = df.keys()
# loop through the sheets to create a po file
for sheet in sheets:
print(sheet)
new_df = pd.read_excel(file+".xlsx", sheet_name=sheet)
filename = file_prefix + "-" + sheet + ".po"
if not os.path.exists(filename):
new_file = open(filename, 'a+')
else:
new_file = open(filename, 'w+')
for p in range(new_df.shape[0]):
new_file.write(new_df['location'][p])
new_file.write("\n")
new_file.write("msgid \"" + str(new_df['source'][p]) + "\"")
new_file.write("\n")
new_file.write("msgstr \"" + str(new_df['target'][p]) + "\"")
new_file.write('\n\n')
new_file.close()