summaryrefslogtreecommitdiff
path: root/languagechecker.py
diff options
context:
space:
mode:
authorRobert Göhler <github@ghlr.de>2023-08-27 21:14:39 +0200
committerGitHub <noreply@github.com>2023-08-27 21:14:39 +0200
commit093055473bb6acba323db69e8e4cbc4c8ac5edca (patch)
tree54b261d0577c48a53695d6cf8392cb130ed2ae0a /languagechecker.py
parent02aafc3df3abebb58832c62ded26c495363ebb3a (diff)
parent355b459f22544c97bd0332ff06dee1d39a05ac07 (diff)
downloadvyos-documentation-093055473bb6acba323db69e8e4cbc4c8ac5edca.tar.gz
vyos-documentation-093055473bb6acba323db69e8e4cbc4c8ac5edca.zip
Merge pull request #1066 from rebortg/localazy-3
Setup translation with localazy
Diffstat (limited to 'languagechecker.py')
-rw-r--r--languagechecker.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/languagechecker.py b/languagechecker.py
new file mode 100644
index 00000000..0305b05b
--- /dev/null
+++ b/languagechecker.py
@@ -0,0 +1,59 @@
+'''
+Parse gettext pot files and extract path:line and msgid information
+compare this with downloaded files from localazy
+the output are the elements which are downloaded but not needed anymore.
+TODO: better output
+'''
+
+import os
+from babel.messages.pofile import read_po
+
+
+def extract_content(file):
+ content = []
+ with open(file) as f:
+ data = read_po(f)
+ for message in data:
+ if message.id:
+ content.append(message)
+ return content
+
+
+gettext_dir = "docs/_build/gettext"
+gettext_ext = ".pot"
+original_content = list()
+
+language_dir = "docs/_locale"
+language_ext = ".pot"
+language_content = dict()
+
+# get gettext filepath
+for (dirpath, dirnames, filenames) in os.walk(gettext_dir):
+ for file in filenames:
+ if gettext_ext in file:
+ original_content.extend(extract_content(f"{dirpath}/{file}"))
+
+# get filepath per language
+languages = next(os.walk(language_dir))[1]
+for language in languages:
+
+ language_content[language] = list()
+ for (dirpath, dirnames, filenames) in os.walk(f"{language_dir}/{language}"):
+ for file in filenames:
+ if language_ext in file:
+ language_content[language].extend(extract_content(f"{dirpath}/{file}"))
+
+
+
+for lang in language_content.keys():
+ for message in language_content[lang]:
+ found = False
+ for ori_message in original_content:
+ if ori_message.id == message.id:
+ found = True
+ if not found:
+ print()
+ print(f"{lang}: {message.id}")
+ for loc in message.locations:
+ print(f"{loc[0]}:{loc[1]}")
+