update extract-po-string to handle plurals again

This commit is contained in:
Damien Elmes 2020-05-05 22:14:39 +10:00
parent 2317574f02
commit 29379a9a50

View file

@ -80,10 +80,12 @@ plurals = json.load(open("plurals.json"))
def plural_text(key, lang, translation):
lang = re.sub("(_|-).*", "", lang)
# extract the variable - there should be only one
# extract the variable - if there's more than one, use the first one
var = re.findall(r"{(\$.*?)}", translation[0])
if not len(var) == 1:
return None
print("multiple variables found, using first replacement")
var = replacements[0][1].replace("{", "").replace("}", "")
else:
var = var[0]
buf = f"{key} = {{ {var} ->\n"
@ -132,9 +134,8 @@ def add_message(fname, key, translation):
if isinstance(translation, str):
add_simple_message(fname, key, translation)
else:
raise
return plural_text(key, lang, translation)
text = plural_text(key, lang, translation)
open(fname, "a").write(text)
print()
input("proceed? ctrl+c to abort")