forked from reddit-archive/reddit-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevert_display_name.py
44 lines (34 loc) · 1.2 KB
/
revert_display_name.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
42
43
44
#!/usr/bin/env python
'''Temporary script to revert the "Display-Name" and
"Display-Name-en" metadata that the transifex client
strips out when running "tx pull".
'''
import fileinput
import os
import subprocess
import sys
COMMAND = "git show HEAD:%s | grep -i display-name"
def get_display_name(filename):
lines = subprocess.check_output(COMMAND % filename, shell=True)
return lines
def has_display_name(filename):
with open(filename) as f:
contents = f.read().lower()
return '\n"display-name' in contents
def write_display_name_lines(filename, lines):
written = False
if has_display_name(filename):
print "%s already has Display-Name lines" % filename
return
for line in fileinput.input(filename, inplace=1, backup=".dn.bak"):
if not written and line.startswith('"Content-Transfer-Encoding'):
for l in lines:
sys.stdout.write(l)
written = True
sys.stdout.write(line)
def handle_lang(lang_path, po_file="r2.po"):
filename = os.path.join(lang_path, po_file)
lines = get_display_name(filename)
write_display_name_lines(filename, lines)
if __name__ == "__main__":
handle_lang(sys.argv[1])