mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
update extract-po-string to handle plurals again
This commit is contained in:
parent
2317574f02
commit
29379a9a50
1 changed files with 7 additions and 6 deletions
|
@ -80,11 +80,13 @@ plurals = json.load(open("plurals.json"))
|
||||||
def plural_text(key, lang, translation):
|
def plural_text(key, lang, translation):
|
||||||
lang = re.sub("(_|-).*", "", lang)
|
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])
|
var = re.findall(r"{(\$.*?)}", translation[0])
|
||||||
if not len(var) == 1:
|
if not len(var) == 1:
|
||||||
return None
|
print("multiple variables found, using first replacement")
|
||||||
var = var[0]
|
var = replacements[0][1].replace("{", "").replace("}", "")
|
||||||
|
else:
|
||||||
|
var = var[0]
|
||||||
|
|
||||||
buf = f"{key} = {{ {var} ->\n"
|
buf = f"{key} = {{ {var} ->\n"
|
||||||
|
|
||||||
|
@ -132,9 +134,8 @@ def add_message(fname, key, translation):
|
||||||
if isinstance(translation, str):
|
if isinstance(translation, str):
|
||||||
add_simple_message(fname, key, translation)
|
add_simple_message(fname, key, translation)
|
||||||
else:
|
else:
|
||||||
raise
|
text = plural_text(key, lang, translation)
|
||||||
return plural_text(key, lang, translation)
|
open(fname, "a").write(text)
|
||||||
|
|
||||||
|
|
||||||
print()
|
print()
|
||||||
input("proceed? ctrl+c to abort")
|
input("proceed? ctrl+c to abort")
|
||||||
|
|
Loading…
Reference in a new issue