catch duplicate keys

This commit is contained in:
Damien Elmes 2020-08-04 11:52:19 +10:00
parent 97bf4da6e8
commit 8d6af167cc

View file

@ -21,7 +21,6 @@ repo_templates_dir = sys.argv[1]
assert os.path.abspath(repo_templates_dir).endswith("templates")
strings = json.load(open("strings.json"))
plurals = json.load(open("plurals.json"))
# i18ndir = os.path.join(ftl_dir, "..")
def transform_entry(entry, replacements):
@ -108,6 +107,10 @@ def add_message(fname, key, translation):
open(fname, "a").write(text)
def key_already_used(key: str) -> bool:
return not subprocess.call(["grep", "-r", f"{key} =", repo_templates_dir])
class Window(QDialog, Ui_Dialog):
def __init__(self):
QDialog.__init__(self)
@ -197,6 +200,10 @@ class Window(QDialog, Ui_Dialog):
def on_add(self):
to_insert = self.get_adjusted_strings()
key = self.get_key()
if key_already_used(key):
QMessageBox.warning(None, "Error", "Duplicate Key")
return
# for each language's translation
for lang, translation in to_insert:
ftl_path = self.filename_for_lang(lang)