From c32360560df99c7b0cabd27896264c03cc5d9e50 Mon Sep 17 00:00:00 2001 From: Vincent Poulailleau Date: Mon, 9 Dec 2019 09:45:24 +0100 Subject: [PATCH] begin glossary checker --- padpo/checkers/glossary.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 padpo/checkers/glossary.py diff --git a/padpo/checkers/glossary.py b/padpo/checkers/glossary.py new file mode 100644 index 0000000..1149762 --- /dev/null +++ b/padpo/checkers/glossary.py @@ -0,0 +1,45 @@ +"""Checker for glossary usage.""" + +from padpo.checkers.baseclass import Checker +from padpo.pofile import PoItem + + +class GlossaryChecker(Checker): + """Checker for glossary usage.""" + + name = "Glossary" + + def check_item(self, item: PoItem): + """Check an item in a `*.po` file.""" + if not item.msgstr_full_content: + return # no warning + original_content = item.msgid_full_content.lower() + translated_content = item.msgstr_full_content.lower() + for word, translations in glossary.items(): + if word.lower() in original_content: + for translated_word in translations: + if translated_word.lower() in translated_content: + break + else: + possibilities = '"' + possibilities += '", "'.join(translations[:-1]) + if len(translations) > 1: + possibilities += '" or "' + possibilities += translations[-1] + possibilities += '"' + item.add_warning( + self.name, + f"Found {word} that is not translated in " + f"{possibilities} in ###{item.msgstr_full_content}" + "###.", + ) + + +# https://github.com/python/python-docs-fr/blob/ +# 8a8a9f8dda4d7f40863f8b0d28f547d84f016ad3/CONTRIBUTING.rst +glossary = { + "-like": ["-compatible"], + "abstract data type": ["type abstrait"], + "argument": ["argument"], + "backslash": ["antislash", "*backslash*", "*backslashes*"], +}