new script to update untranslated messages from other language file
This commit is contained in:
@@ -995,6 +995,23 @@ def update_all_languages(application_path):
|
|||||||
findT(application_path, language[:-3])
|
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__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user