diff --git a/qt/i18n/extract-po-string.py b/qt/i18n/extract-po-string.py index d460d0fe0..7b3b5b6be 100644 --- a/qt/i18n/extract-po-string.py +++ b/qt/i18n/extract-po-string.py @@ -1,4 +1,8 @@ import os + +import json + +import re import sys import polib @@ -34,6 +38,47 @@ for (lang, cat) in cats: print(lang, "has", msg) to_insert.append((lang, msg)) break + elif entry.msgstr_plural and entry.msgstr_plural[0]: + # convert the dict into a list in the correct order + plurals = list(entry.msgstr_plural.items()) + plurals.sort() + # update variables and discard keys + adjusted = [] + for _k, msg in plurals: + if replacements: + for (old,new) in replacements: + msg = msg.replace(old, f"{{${new}}}") + adjusted.append(msg) + print(lang, "has", adjusted) + if len(adjusted) > 1: + to_insert.append((lang, adjusted)) + else: + # language doesn't have plurals + to_insert.append((lang, adjusted[0])) + +plurals = json.load(open("plurals.json")) + +def plural_text(key, lang, translation): + lang = re.sub("(_|-).*", "", lang) + + # extract the variable - there should be only one + var = re.findall(r"{(\$.*?)}", translation[0]) + if not len(var) == 1: + return None + var = var[0] + + buf = f"{key} = {{ {var} ->\n" + + # for each of the plural forms except the last + for idx, msg in enumerate(translation[:-1]): + plural_form = plurals[lang][idx] + buf += f" [{plural_form}] {msg}\n" + + # add the catchall + msg = translation[-1] + buf += f" *[other] {msg}\n" + buf += " }\n" + return buf for lang, translation in to_insert: dir = os.path.join("ftl", "core", lang) @@ -45,6 +90,13 @@ for lang, translation in to_insert: if not os.path.exists(dir): os.mkdir(dir) - open(ftl_path, "a").write(f"\n{key} = {translation}\n") + # simple, non-plural form? + if isinstance(translation, str): + buf = f"{key} = {translation}\n" + else: + buf = plural_text(key, lang, translation) + + if buf: + open(ftl_path, "a").write(buf) print("done") diff --git a/qt/i18n/plurals.json b/qt/i18n/plurals.json new file mode 100644 index 000000000..bac5eda6a --- /dev/null +++ b/qt/i18n/plurals.json @@ -0,0 +1,889 @@ +{ + "af": [ + "one", + "other" + ], + "ak": [ + "one", + "other" + ], + "am": [ + "one", + "other" + ], + "an": [ + "one", + "other" + ], + "ar": [ + "zero", + "one", + "two", + "few", + "many", + "other" + ], + "ars": [ + "zero", + "one", + "two", + "few", + "many", + "other" + ], + "as": [ + "one", + "other" + ], + "asa": [ + "one", + "other" + ], + "ast": [ + "one", + "other" + ], + "az": [ + "one", + "other" + ], + "be": [ + "one", + "few", + "many", + "other" + ], + "bem": [ + "one", + "other" + ], + "bez": [ + "one", + "other" + ], + "bg": [ + "one", + "other" + ], + "bho": [ + "one", + "other" + ], + "bm": [ + "other" + ], + "bn": [ + "one", + "other" + ], + "bo": [ + "other" + ], + "br": [ + "one", + "two", + "few", + "many", + "other" + ], + "brx": [ + "one", + "other" + ], + "bs": [ + "one", + "few", + "other" + ], + "ca": [ + "one", + "other" + ], + "ce": [ + "one", + "other" + ], + "ceb": [ + "one", + "other" + ], + "cgg": [ + "one", + "other" + ], + "chr": [ + "one", + "other" + ], + "ckb": [ + "one", + "other" + ], + "cs": [ + "one", + "few", + "many", + "other" + ], + "cy": [ + "zero", + "one", + "two", + "few", + "many", + "other" + ], + "da": [ + "one", + "other" + ], + "de": [ + "one", + "other" + ], + "dsb": [ + "one", + "two", + "few", + "other" + ], + "dv": [ + "one", + "other" + ], + "dz": [ + "other" + ], + "ee": [ + "one", + "other" + ], + "el": [ + "one", + "other" + ], + "en": [ + "one", + "other" + ], + "eo": [ + "one", + "other" + ], + "es": [ + "one", + "other" + ], + "et": [ + "one", + "other" + ], + "eu": [ + "one", + "other" + ], + "fa": [ + "one", + "other" + ], + "ff": [ + "one", + "other" + ], + "fi": [ + "one", + "other" + ], + "fil": [ + "one", + "other" + ], + "fo": [ + "one", + "other" + ], + "fr": [ + "one", + "other" + ], + "fur": [ + "one", + "other" + ], + "fy": [ + "one", + "other" + ], + "ga": [ + "one", + "two", + "few", + "many", + "other" + ], + "gd": [ + "one", + "two", + "few", + "other" + ], + "gl": [ + "one", + "other" + ], + "gsw": [ + "one", + "other" + ], + "gu": [ + "one", + "other" + ], + "guw": [ + "one", + "other" + ], + "gv": [ + "one", + "two", + "few", + "many", + "other" + ], + "ha": [ + "one", + "other" + ], + "haw": [ + "one", + "other" + ], + "he": [ + "one", + "two", + "many", + "other" + ], + "hi": [ + "one", + "other" + ], + "hr": [ + "one", + "few", + "other" + ], + "hsb": [ + "one", + "two", + "few", + "other" + ], + "hu": [ + "one", + "other" + ], + "hy": [ + "one", + "other" + ], + "ia": [ + "one", + "other" + ], + "id": [ + "other" + ], + "ig": [ + "other" + ], + "ii": [ + "other" + ], + "in": [ + "other" + ], + "io": [ + "one", + "other" + ], + "is": [ + "one", + "other" + ], + "it": [ + "one", + "other" + ], + "iu": [ + "one", + "two", + "other" + ], + "iw": [ + "one", + "two", + "many", + "other" + ], + "ja": [ + "other" + ], + "jbo": [ + "other" + ], + "jgo": [ + "one", + "other" + ], + "ji": [ + "one", + "other" + ], + "jmc": [ + "one", + "other" + ], + "jv": [ + "other" + ], + "jw": [ + "other" + ], + "ka": [ + "one", + "other" + ], + "kab": [ + "one", + "other" + ], + "kaj": [ + "one", + "other" + ], + "kcg": [ + "one", + "other" + ], + "kde": [ + "other" + ], + "kea": [ + "other" + ], + "kk": [ + "one", + "other" + ], + "kkj": [ + "one", + "other" + ], + "kl": [ + "one", + "other" + ], + "km": [ + "other" + ], + "kn": [ + "one", + "other" + ], + "ko": [ + "other" + ], + "ks": [ + "one", + "other" + ], + "ksb": [ + "one", + "other" + ], + "ksh": [ + "zero", + "one", + "other" + ], + "ku": [ + "one", + "other" + ], + "kw": [ + "zero", + "one", + "two", + "few", + "many", + "other" + ], + "ky": [ + "one", + "other" + ], + "lag": [ + "zero", + "one", + "other" + ], + "lb": [ + "one", + "other" + ], + "lg": [ + "one", + "other" + ], + "lkt": [ + "other" + ], + "ln": [ + "one", + "other" + ], + "lo": [ + "other" + ], + "lt": [ + "one", + "few", + "many", + "other" + ], + "lv": [ + "zero", + "one", + "other" + ], + "mas": [ + "one", + "other" + ], + "mg": [ + "one", + "other" + ], + "mgo": [ + "one", + "other" + ], + "mk": [ + "one", + "other" + ], + "ml": [ + "one", + "other" + ], + "mn": [ + "one", + "other" + ], + "mo": [ + "one", + "few", + "other" + ], + "mr": [ + "one", + "other" + ], + "ms": [ + "other" + ], + "mt": [ + "one", + "few", + "many", + "other" + ], + "my": [ + "other" + ], + "nah": [ + "one", + "other" + ], + "naq": [ + "one", + "two", + "other" + ], + "nb": [ + "one", + "other" + ], + "nd": [ + "one", + "other" + ], + "ne": [ + "one", + "other" + ], + "nl": [ + "one", + "other" + ], + "nn": [ + "one", + "other" + ], + "nnh": [ + "one", + "other" + ], + "no": [ + "one", + "other" + ], + "nqo": [ + "other" + ], + "nr": [ + "one", + "other" + ], + "nso": [ + "one", + "other" + ], + "ny": [ + "one", + "other" + ], + "nyn": [ + "one", + "other" + ], + "om": [ + "one", + "other" + ], + "or": [ + "one", + "other" + ], + "os": [ + "one", + "other" + ], + "osa": [ + "other" + ], + "pa": [ + "one", + "other" + ], + "pap": [ + "one", + "other" + ], + "pl": [ + "one", + "few", + "many", + "other" + ], + "prg": [ + "zero", + "one", + "other" + ], + "ps": [ + "one", + "other" + ], + "pt": [ + "one", + "other" + ], + "pt-PT": [ + "one", + "other" + ], + "rm": [ + "one", + "other" + ], + "ro": [ + "one", + "few", + "other" + ], + "rof": [ + "one", + "other" + ], + "root": [ + "other" + ], + "ru": [ + "one", + "few", + "many", + "other" + ], + "rwk": [ + "one", + "other" + ], + "sah": [ + "other" + ], + "saq": [ + "one", + "other" + ], + "sc": [ + "one", + "other" + ], + "scn": [ + "one", + "other" + ], + "sd": [ + "one", + "other" + ], + "sdh": [ + "one", + "other" + ], + "se": [ + "one", + "two", + "other" + ], + "seh": [ + "one", + "other" + ], + "ses": [ + "other" + ], + "sg": [ + "other" + ], + "sh": [ + "one", + "few", + "other" + ], + "shi": [ + "one", + "few", + "other" + ], + "si": [ + "one", + "other" + ], + "sk": [ + "one", + "few", + "many", + "other" + ], + "sl": [ + "one", + "two", + "few", + "other" + ], + "sma": [ + "one", + "two", + "other" + ], + "smi": [ + "one", + "two", + "other" + ], + "smj": [ + "one", + "two", + "other" + ], + "smn": [ + "one", + "two", + "other" + ], + "sms": [ + "one", + "two", + "other" + ], + "sn": [ + "one", + "other" + ], + "so": [ + "one", + "other" + ], + "sq": [ + "one", + "other" + ], + "sr": [ + "one", + "few", + "other" + ], + "ss": [ + "one", + "other" + ], + "ssy": [ + "one", + "other" + ], + "st": [ + "one", + "other" + ], + "su": [ + "other" + ], + "sv": [ + "one", + "other" + ], + "sw": [ + "one", + "other" + ], + "syr": [ + "one", + "other" + ], + "ta": [ + "one", + "other" + ], + "te": [ + "one", + "other" + ], + "teo": [ + "one", + "other" + ], + "th": [ + "other" + ], + "ti": [ + "one", + "other" + ], + "tig": [ + "one", + "other" + ], + "tk": [ + "one", + "other" + ], + "tl": [ + "one", + "other" + ], + "tn": [ + "one", + "other" + ], + "to": [ + "other" + ], + "tr": [ + "one", + "other" + ], + "ts": [ + "one", + "other" + ], + "tzm": [ + "one", + "other" + ], + "ug": [ + "one", + "other" + ], + "uk": [ + "one", + "few", + "many", + "other" + ], + "ur": [ + "one", + "other" + ], + "uz": [ + "one", + "other" + ], + "ve": [ + "one", + "other" + ], + "vi": [ + "other" + ], + "vo": [ + "one", + "other" + ], + "vun": [ + "one", + "other" + ], + "wa": [ + "one", + "other" + ], + "wae": [ + "one", + "other" + ], + "wo": [ + "other" + ], + "xh": [ + "one", + "other" + ], + "xog": [ + "one", + "other" + ], + "yi": [ + "one", + "other" + ], + "yo": [ + "other" + ], + "yue": [ + "other" + ], + "zh": [ + "other" + ], + "zu": [ + "one", + "other" + ], + "oc": + ["one", "other"], + "la": + ["one", "other"] +}