From cdac608efc52cda3e008915e134dac76d59541a7 Mon Sep 17 00:00:00 2001 From: zvolsky Date: Thu, 10 Mar 2016 09:48:04 +0100 Subject: [PATCH] new script to update untranslated messages from other language file --- gluon/languages.py | 17 +++++++++++++ scripts/lang_update_from_langfile.py | 37 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 scripts/lang_update_from_langfile.py diff --git a/gluon/languages.py b/gluon/languages.py index 14b02c04..e1908c1b 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -995,6 +995,23 @@ def update_all_languages(application_path): findT(application_path, language[:-3]) +def update_from_langfile(target, source): + """this will update untranslated messages in target from source (where both are language files) + this can be used as first step when creating language file for new but very similar language + or if you want update your app from welcome app of newer web2py version + or in non-standard scenarios when you work on target and from any reason you have partial translation in source + """ + src = read_dict(source) + sentences = read_dict(target) + for key in sentences: + val = sentences[key] + if not val or val == key: + new_val = src.get(key) + if new_val and new_val != val: + sentences[key] = new_val + write_dict(target, sentences) + + if __name__ == '__main__': import doctest doctest.testmod() diff --git a/scripts/lang_update_from_langfile.py b/scripts/lang_update_from_langfile.py new file mode 100644 index 00000000..4ce93a0b --- /dev/null +++ b/scripts/lang_update_from_langfile.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +This script will update untranslated messages in target from source (target and source are both language files) +Usage: + this can be used as first step when creating language file for new but very similar language + or if you want update your app from welcome app of newer web2py version + or in non-standard scenarios when you work on target and from any reason you have partial translation in source +""" + +import sys +import os +sys.path.append(os.path.join(*__file__.split(os.sep)[:-2] or ['.'])) + +from gluon.languages import update_from_langfile +import argparse + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Use to set untranslated messages in the translation file from another one.') + parser.add_argument( + '-t', '--target', + required=True, + dest="target", + help="Specify language file (rw) where untranslated messages will be updated if possible" + ) + parser.add_argument( + '-s', '--source', + required=True, + dest="source", + help="Specify language file (ro) where seek for translations" + ) + args = parser.parse_args() + + update_from_langfile(args.target, args.source) + + print '%s was updated.' % args.target