fixed sync languages, thanks Yair

This commit is contained in:
Massimo
2012-10-30 11:09:50 -05:00
parent 5713ec1365
commit c404db4a08
2 changed files with 40 additions and 33 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.2.1 (2012-10-30 09:41:34) stable Version 2.2.1 (2012-10-30 11:09:19) stable
+38 -31
View File
@@ -7,14 +7,10 @@ import sys
import shutil import shutil
import os import os
from gluon.languages import findT, utf8_repr from gluon.languages import findT
sys.path.insert(0, '.') sys.path.insert(0, '.')
file = sys.argv[1]
apps = sys.argv[2:]
def sync_language(d, data): def sync_language(d, data):
''' this function makes sure a translated string will be prefered over an untranslated ''' this function makes sure a translated string will be prefered over an untranslated
string when syncing languages between apps. when both are translated, it prefers the string when syncing languages between apps. when both are translated, it prefers the
@@ -37,35 +33,46 @@ def sync_language(d, data):
return d return d
d = {} def sync_main(file, apps):
for app in apps: d = {}
path = 'applications/%s/' % app for app in apps:
findT(path, file) path = 'applications/%s/' % app
langfile = open(os.path.join(path, 'languages', '%s.py' % file)) findT(path, file)
langfile = open(os.path.join(path, 'languages', '%s.py' % file))
try:
data = eval(langfile.read())
finally:
langfile.close()
d = sync_language(d, data)
path = 'applications/%s/' % apps[-1]
file1 = os.path.join(path, 'languages', '%s.py' % file)
f = open(file1, 'w')
try: try:
data = eval(langfile.read()) f.write('# coding: utf8\n')
f.write('{\n')
keys = d.keys()
keys.sort()
for key in keys:
f.write("'''%s''':'''%s''',\n" % (key.replace("'", "\\'"), str(d[key].replace("'", "\\'"))))
f.write('}\n')
finally: finally:
langfile.close() f.close()
d = sync_language(d, data) oapps = reversed(apps[:-1])
for app in oapps:
path2 = 'applications/%s/' % app
file2 = os.path.join(path2, 'languages', '%s.py' % file)
if file1 != file2:
shutil.copyfile(file1, file2)
path = 'applications/%s/' % apps[-1] if __name__ == "__main__":
file1 = os.path.join(path, 'languages', '%s.py' % file)
f = open(file1, 'w') file = sys.argv[1]
try: apps = sys.argv[2:]
f.write('# coding: utf8\n')
f.write('{\n') sync_main(file, apps)
keys = d.keys()
keys.sort()
for key in keys:
f.write('%s:%s,\n' % (utf8_repr(key), utf8_repr(str(d[key]))))
f.write('}\n')
finally:
f.close()
oapps = reversed(apps[:-1])
for app in oapps:
path2 = 'applications/%s/' % app
file2 = os.path.join(path2, 'languages', '%s.py' % file)
shutil.copyfile(file1, file2)