support variables when importing from gettext
This commit is contained in:
parent
232a8625bf
commit
7b26814922
@ -5,8 +5,13 @@ import polib
|
|||||||
|
|
||||||
# extract a translated string from the gettext catalogs and insert it into ftl
|
# extract a translated string from the gettext catalogs and insert it into ftl
|
||||||
# eg:
|
# eg:
|
||||||
# $ python extract-po-string.py media-check.ftl delete-unused "Delete Unused Media" 1
|
# $ 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 "%(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...")
|
print("Loading catalogs...")
|
||||||
base = "po/desktop"
|
base = "po/desktop"
|
||||||
@ -22,8 +27,12 @@ for (lang, cat) in cats:
|
|||||||
for entry in cat:
|
for entry in cat:
|
||||||
if entry.msgid == msgid:
|
if entry.msgid == msgid:
|
||||||
if entry.msgstr:
|
if entry.msgstr:
|
||||||
print(lang, "has", entry.msgstr)
|
msg = entry.msgstr
|
||||||
to_insert.append((lang, 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
|
break
|
||||||
|
|
||||||
for lang, translation in to_insert:
|
for lang, translation in to_insert:
|
||||||
|
Loading…
Reference in New Issue
Block a user