mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
catch duplicate keys
This commit is contained in:
parent
97bf4da6e8
commit
8d6af167cc
1 changed files with 8 additions and 1 deletions
|
@ -21,7 +21,6 @@ repo_templates_dir = sys.argv[1]
|
||||||
assert os.path.abspath(repo_templates_dir).endswith("templates")
|
assert os.path.abspath(repo_templates_dir).endswith("templates")
|
||||||
strings = json.load(open("strings.json"))
|
strings = json.load(open("strings.json"))
|
||||||
plurals = json.load(open("plurals.json"))
|
plurals = json.load(open("plurals.json"))
|
||||||
# i18ndir = os.path.join(ftl_dir, "..")
|
|
||||||
|
|
||||||
|
|
||||||
def transform_entry(entry, replacements):
|
def transform_entry(entry, replacements):
|
||||||
|
@ -108,6 +107,10 @@ def add_message(fname, key, translation):
|
||||||
open(fname, "a").write(text)
|
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):
|
class Window(QDialog, Ui_Dialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QDialog.__init__(self)
|
QDialog.__init__(self)
|
||||||
|
@ -197,6 +200,10 @@ class Window(QDialog, Ui_Dialog):
|
||||||
def on_add(self):
|
def on_add(self):
|
||||||
to_insert = self.get_adjusted_strings()
|
to_insert = self.get_adjusted_strings()
|
||||||
key = self.get_key()
|
key = self.get_key()
|
||||||
|
if key_already_used(key):
|
||||||
|
QMessageBox.warning(None, "Error", "Duplicate Key")
|
||||||
|
return
|
||||||
|
|
||||||
# for each language's translation
|
# for each language's translation
|
||||||
for lang, translation in to_insert:
|
for lang, translation in to_insert:
|
||||||
ftl_path = self.filename_for_lang(lang)
|
ftl_path = self.filename_for_lang(lang)
|
||||||
|
|
Loading…
Reference in a new issue