script for language files update has new param to update existing translations
This commit is contained in:
+4
-2
@@ -1002,17 +1002,19 @@ def update_all_languages(application_path):
|
|||||||
findT(application_path, language[:-3])
|
findT(application_path, language[:-3])
|
||||||
|
|
||||||
|
|
||||||
def update_from_langfile(target, source):
|
def update_from_langfile(target, source, force_update=False):
|
||||||
"""this will update untranslated messages in target from source (where both are language files)
|
"""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
|
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 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
|
or in non-standard scenarios when you work on target and from any reason you have partial translation in source
|
||||||
|
Args:
|
||||||
|
force_update: if False existing translations remain unchanged, if True existing translations will update from source
|
||||||
"""
|
"""
|
||||||
src = read_dict(source)
|
src = read_dict(source)
|
||||||
sentences = read_dict(target)
|
sentences = read_dict(target)
|
||||||
for key in sentences:
|
for key in sentences:
|
||||||
val = sentences[key]
|
val = sentences[key]
|
||||||
if not val or val == key:
|
if not val or val == key or force_update:
|
||||||
new_val = src.get(key)
|
new_val = src.get(key)
|
||||||
if new_val and new_val != val:
|
if new_val and new_val != val:
|
||||||
sentences[key] = new_val
|
sentences[key] = new_val
|
||||||
|
|||||||
Regular → Executable
+8
-1
@@ -30,8 +30,15 @@ if __name__ == '__main__':
|
|||||||
dest="source",
|
dest="source",
|
||||||
help="Specify language file (ro) where seek for translations"
|
help="Specify language file (ro) where seek for translations"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-f', '--force-update',
|
||||||
|
dest="force_update",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="without it: add new + translate untranslated, if used: in addition update items if translation differs"
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
update_from_langfile(args.target, args.source)
|
update_from_langfile(args.target, args.source, force_update=args.force_update)
|
||||||
|
|
||||||
print '%s was updated.' % args.target
|
print '%s was updated.' % args.target
|
||||||
|
|||||||
Reference in New Issue
Block a user