support variables when importing from gettext

This commit is contained in:
Damien Elmes 2020-02-20 12:49:10 +10:00
parent 232a8625bf
commit 7b26814922

View File

@ -5,8 +5,13 @@ import polib
# extract a translated string from the gettext catalogs and insert it into ftl
# eg:
# $ python extract-po-string.py media-check.ftl delete-unused "Delete Unused Media" 1
ftl_filename, key, msgid, dry_run = sys.argv[1:]
# $ python extract-po-string.py media-check.ftl delete-unused "Delete Unused Media" "", 1
# $ python extract-po-string.py media-check.ftl delete-unused "%(a)s %(b)s" "%(a)s=val1,%(b)s=val2" 0
ftl_filename, key, msgid, repls, dry_run = sys.argv[1:]
replacements = []
for repl in repls.split(","):
replacements.append(repl.split("="))
print("Loading catalogs...")
base = "po/desktop"
@ -22,8 +27,12 @@ for (lang, cat) in cats:
for entry in cat:
if entry.msgid == msgid:
if entry.msgstr:
print(lang, "has", entry.msgstr)
to_insert.append((lang, entry.msgstr))
msg = entry.msgstr
if replacements:
for (old,new) in replacements:
msg = msg.replace(old, f"{{${new}}}")
print(lang, "has", msg)
to_insert.append((lang, msg))
break
for lang, translation in to_insert: