From c2b4f0e17866d8d09e442d122cfecea6b72e2ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Fri, 17 Apr 2020 16:52:27 +0200 Subject: [PATCH 1/3] Check for unused translations --- Makefile | 1 + tests/check-for-unused-translations.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 tests/check-for-unused-translations.py diff --git a/Makefile b/Makefile index f0d1dc1d..1791c4c7 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ check-translations: @-$(foreach lang,$(languages), \ msgcmp resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \ ) + @tests/check-for-unused-translations.py check-addon: clean @echo -e "$(white)=$(blue) Starting sanity addon tests$(reset)" diff --git a/tests/check-for-unused-translations.py b/tests/check-for-unused-translations.py new file mode 100755 index 00000000..bf2e02ed --- /dev/null +++ b/tests/check-for-unused-translations.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +""" Quick and dirty way to check if all translations might be used. """ +# -*- coding: utf-8 -*- + +import subprocess + +import polib + +error = 0 + +# Load all python code from git +code = subprocess.check_output(['git', 'grep', '', '--', 'resources/*.py', 'resources/settings.xml']).decode('utf-8') + +# Load po file +po = polib.pofile('resources/language/resource.language.en_gb/strings.po') +for entry in po: + # Extract msgctxt + msgctxt = entry.msgctxt.lstrip('#') + + if msgctxt not in code: + print('No usage found for translation:') + print(entry) + error = 1 + +exit(error) From b67b2d072a3e93a2dc6583f1c2415f5e7e0f302f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Fri, 17 Apr 2020 16:59:31 +0200 Subject: [PATCH 2/3] Update for pylint --- Makefile | 2 +- ...ed-translations.py => check_for_unused_translations.py} | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) rename tests/{check-for-unused-translations.py => check_for_unused_translations.py} (91%) diff --git a/Makefile b/Makefile index 1791c4c7..064185ea 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ check-translations: @-$(foreach lang,$(languages), \ msgcmp resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \ ) - @tests/check-for-unused-translations.py + @tests/check_for_unused_translations.py check-addon: clean @echo -e "$(white)=$(blue) Starting sanity addon tests$(reset)" diff --git a/tests/check-for-unused-translations.py b/tests/check_for_unused_translations.py similarity index 91% rename from tests/check-for-unused-translations.py rename to tests/check_for_unused_translations.py index bf2e02ed..3aff3320 100755 --- a/tests/check-for-unused-translations.py +++ b/tests/check_for_unused_translations.py @@ -1,8 +1,11 @@ #!/usr/bin/env python -""" Quick and dirty way to check if all translations might be used. """ # -*- coding: utf-8 -*- +""" Quick and dirty way to check if all translations might be used. """ + +# pylint: disable=invalid-name import subprocess +import sys import polib @@ -22,4 +25,4 @@ print(entry) error = 1 -exit(error) +sys.exit(error) From 71604fd48fd25bb4690f428f26faa0210332398e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Fri, 17 Apr 2020 17:03:47 +0200 Subject: [PATCH 3/3] Make python 2.7 also happy --- tests/check_for_unused_translations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/check_for_unused_translations.py b/tests/check_for_unused_translations.py index 3aff3320..3122bb08 100755 --- a/tests/check_for_unused_translations.py +++ b/tests/check_for_unused_translations.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ Quick and dirty way to check if all translations might be used. """ -# pylint: disable=invalid-name +# pylint: disable=invalid-name,superfluous-parens import subprocess import sys