diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-02-22 13:36:51 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-02-22 13:36:51 -0300 |
commit | 953e605537738045ceff54859f6ee39f75460f6f (patch) | |
tree | 93318ab703e9142a9443c0e6eb0fc80d74a63f3e /askbot/bin | |
parent | 193ad161b9123eeff8a22b3d6c0303d0f7d3b875 (diff) | |
download | askbot-953e605537738045ceff54859f6ee39f75460f6f.tar.gz askbot-953e605537738045ceff54859f6ee39f75460f6f.tar.bz2 askbot-953e605537738045ceff54859f6ee39f75460f6f.zip |
merged translations from the repository with those in the document foundation pootle system
Diffstat (limited to 'askbot/bin')
-rw-r--r-- | askbot/bin/mergelocales.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/askbot/bin/mergelocales.py b/askbot/bin/mergelocales.py new file mode 100644 index 00000000..2c49cb25 --- /dev/null +++ b/askbot/bin/mergelocales.py @@ -0,0 +1,61 @@ +import os +import sys +import shutil +import subprocess + +DIR1 = sys.argv[1] +DIR2 = sys.argv[2] +DEST_DIR = sys.argv[3] + +def get_locale_list(path): + """return names of directories within a locale dir""" + items = os.listdir(path) + result = list() + for item in items: + if os.path.isdir(os.path.join(path, item)): + result.append(item) + return result + +def copy_locale_from(localeno, name = None): + """copy entire locale without merging""" + if localeno == 1: + src = os.path.join(DIR1, name) + elif localeno == 2: + src = os.path.join(DIR2, name) + shutil.copytree(src, os.path.join(DEST_DIR, name)) + +def merge_locales(name): + """runs msgcat command on specified files + and a locale name in DIR1 and DIR2""" + run_msgcat(name, 'django.po') + run_msgcat(name, 'djangojs.po') + +def run_msgcat(locale_name, file_name): + """run msgcat in locale on file name""" + file_path = os.path.join(locale_name, 'LC_MESSAGES', file_name) + dest_file = os.path.join(DEST_DIR, file_path) + dest_dir = os.path.dirname(dest_file) + if not os.path.exists(dest_dir): + os.makedirs(os.path.dirname(dest_file)) + subprocess.call(( + 'msgcat', + os.path.join(DIR1, file_path), + os.path.join(DIR2, file_path), + '-o', + dest_file + )) + +LOCALE_LIST1 = get_locale_list(DIR1) +LOCALE_LIST2 = get_locale_list(DIR2) + +for locale in LOCALE_LIST1: + print locale + if locale not in LOCALE_LIST2: + copy_locale_from(1, name = locale) + else: + merge_locales(locale) + LOCALE_LIST2.remove(locale) + +for locale in LOCALE_LIST2: + print locale + copy_locale_from(2, name = locale) |