commit 8065b699637b39655452f0e9c5cbfe1c3ffb5f25 Author: Lukas Winkler Date: Sat Aug 10 15:54:51 2019 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61447b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ + +# Created by https://www.gitignore.io/api/python +# Edit at https://www.gitignore.io/?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# End of https://www.gitignore.io/api/python + +.idea diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..589223b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +python: + - "3.7" +install: + - git clone https://github.com/matomo-org/matomo.git + - cp config.travis.py config.py +script: + - python translation_placeholders.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..a0f7d2a --- /dev/null +++ b/config.py @@ -0,0 +1,3 @@ +from pathlib import Path + +matomo_path = Path("/home/lukas/public_html/piwik") diff --git a/config.travis.py b/config.travis.py new file mode 100644 index 0000000..dab611a --- /dev/null +++ b/config.travis.py @@ -0,0 +1,3 @@ +from pathlib import Path + +matomo_path = Path("./matomo") diff --git a/translation_placeholders.py b/translation_placeholders.py new file mode 100644 index 0000000..6499cee --- /dev/null +++ b/translation_placeholders.py @@ -0,0 +1,64 @@ +import json +import re + +from config import matomo_path + +lang_dirs = [matomo_path / "lang"] + +pluginspath = matomo_path / "plugins" + +regex = re.compile(r"%[sducoxXbgGeEfF]") +typo_regex = re.compile(r"%%[sducoxXbgGeEfF]") +fail = False +for plugindir in pluginspath.iterdir(): + if not plugindir.is_dir(): + continue + if "UptimeRobotMonitor" in str(plugindir): + continue + langdir = plugindir / "lang" + if langdir.exists(): + lang_dirs.append(langdir) + +for langdir in lang_dirs: + with open(langdir / "en.json") as f: + data = json.load(f) + placeholders = {} + master_translations = list(data.values())[0] + for key, translation in master_translations.items(): + typos = typo_regex.findall(translation) + if typos: + print(typos) + num_placeholders = len(regex.findall(translation)) + placeholders[key] = num_placeholders + + for transfile in langdir.glob("*.json"): + if transfile == langdir / "en.json": + continue + lang = transfile.stem + with open(transfile) as f: + data = json.load(f) + translations = list(data.values())[0] + for key, translation in translations.items(): + typos = typo_regex.findall(translation) + if typos: + print(transfile) + print(typos, translation) + print() + fail = True + num_placeholders = len(regex.findall(translation)) + try: + if placeholders[key] != num_placeholders: + print(transfile) + print(placeholders[key], num_placeholders) + print(master_translations[key]) + print(translations[key]) + print() + fail = True + except KeyError: + print(transfile) + print(f"Key '{key}' is only in {lang}") + print() + fail = True + +if fail: + exit(1)