test-translations: display all hotkey conflicts at once

... instead of erroring out at the first conflict.

Also display all options involved in a hotkey conflict to make fixing it
easier.
This commit is contained in:
Christian Boltz 2025-02-23 16:45:15 +01:00
parent d52b301ee8
commit 3e7e9bf01f
Failed to generate hash of commit

View file

@ -59,6 +59,8 @@ class TestHotkeyConflicts(AATest):
# we also want to detect hotkey conflicts in the untranslated english strings
self.languages.append('C')
conflicts = []
for language in self.languages:
with self.subTest(language=language):
t = gettext.translation(
@ -67,15 +69,25 @@ class TestHotkeyConflicts(AATest):
)
keys = {}
all_keys = []
found_conflict = ''
for key in params:
text = t.gettext(CMDS[key])
all_keys.append(text)
hotkey = get_translated_hotkey(text)
if keys.get(hotkey):
raise Exception("Hotkey conflict: '{}' and '{}'".format(keys[hotkey], text))
found_conflict = "Hotkey conflict for {}: '{}' and '{}'".format(language, keys[hotkey], text)
else:
keys[hotkey] = text
if found_conflict:
conflicts.append("{}\n {}'".format(found_conflict, ' '.join(all_keys)))
if conflicts:
raise Exception('\n'.join(conflicts))
setup_all_loops(__name__)
if __name__ == '__main__':