Update Python 3 compatibility

This commit is contained in:
Vinyl Darkscratch
2019-02-09 00:01:11 -08:00
parent fcea326855
commit f434ebec8a
29 changed files with 112 additions and 152 deletions
+6 -10
View File
@@ -14,15 +14,14 @@ parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
from gluon.cfs import getcfs
from gluon.utf8 import Utf8
from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode, to_bytes, iteritems, to_native, pjoin
from gluon.languages import findT
from gluon.languages import findT, sort_function
# This script can be run with no arguments (which sets the application folder to the current working directory, and default language to English), one argument (which sets the default language), or two arguments (application folder path and default language).
# When run, it will update the default language, as well as strip all of the strings found in the non-default languages but not in the default language, and add the strings found in the default language to the non-default languages it is not, making sure translators don't do additional work that will never be used.
def read_dict_aux(filename):
lang_text = open(filename, 'r').read().replace(b'\r\n', b'\n')
lang_text = open(filename, 'r').read().replace('\r\n', '\n')
try:
return safe_eval(to_native(lang_text)) or {}
except Exception:
@@ -41,14 +40,11 @@ def safe_eval(text):
return eval(text, {}, {})
return None
def sort_function(x, y):
return cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())
def write_file(file, contents):
file.write('# -*- coding: utf-8 -*-\n{\n')
for key in sorted(contents, sort_function):
file.write('%s: %s,\n' % (repr(Utf8(key)),
repr(Utf8(contents[key]))))
for key in sorted(contents, key = sort_function):
file.write('%s: %s,\n' % (repr(to_unicode(key)),
repr(to_unicode(contents[key]))))
file.write('}\n')
file.close()
@@ -67,7 +63,7 @@ def update_languages(cwd, default_lang):
if phrase in default:
new_dict[phrase] = i18n[phrase]
write_file(open(os.path.join(cwd, "languages", lang), 'w'), new_dict)
print lang
print(lang)
if __name__ == "__main__":
cwd = os.getcwd()