From e0e1fe2db42dc6bfa90acfdc0fc64bd55885b29a Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Wed, 25 Aug 2021 12:21:56 +0200 Subject: [PATCH] intial collection --- .gitignore | 3 +++ missing_languages.py | 28 +++++++++++++++++++++ sortTranslationKeys.py | 25 ++++++++++++++++++ weblate/mass-edit.py | 57 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 .gitignore create mode 100644 missing_languages.py create mode 100644 sortTranslationKeys.py create mode 100644 weblate/mass-edit.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec2f4c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +config.py +*.csv diff --git a/missing_languages.py b/missing_languages.py new file mode 100644 index 0000000..1536cea --- /dev/null +++ b/missing_languages.py @@ -0,0 +1,28 @@ +from pathlib import Path + +lang_dir = Path("../lang") + +languages_in_matomo = set(str(dir.stem) for dir in lang_dir.glob("*.json")) + +print(len(languages_in_matomo)) + +languages_in_transifex = set() +completenesses = {} +names = {} +with open("matomo_matomo.languages.csv") as f: + next(f) + for line in f: + cols = line.split(",") + name = cols[0] + code = cols[1].replace("_", "-").lower() + if code == "-": + continue + completeness = 100 - float(cols[3][:-1]) + languages_in_transifex.add(code) + completenesses[code] = completeness + names[code] = name + +assert languages_in_matomo - languages_in_transifex == {"dev"} + +for code in languages_in_transifex - languages_in_matomo: + print(code, names[code], f"{completenesses[code]:.2f}% complete") diff --git a/sortTranslationKeys.py b/sortTranslationKeys.py new file mode 100644 index 0000000..b6c940f --- /dev/null +++ b/sortTranslationKeys.py @@ -0,0 +1,25 @@ +import json +from pathlib import Path + +matomo_dir = Path("..") +files = sorted(matomo_dir.glob("**/en.json")) +for file in files: + plugin_json = file.parent.parent / "plugin.json" + if not plugin_json.exists(): + continue + with plugin_json.open() as f: + plugin_data = json.load(f) + if "authors" not in plugin_data: + continue + if plugin_data["authors"][0]["name"] != "Lukas Winkler": + continue + if plugin_data["name"] != "DiagnosticsExtended": + continue + print(file) + + with file.open("r") as f: + data = json.load(f) + + with file.open("w") as f: + json.dump(data, f, indent=4, ensure_ascii=False, sort_keys=True) + f.write("\n") diff --git a/weblate/mass-edit.py b/weblate/mass-edit.py new file mode 100644 index 0000000..80ddfd4 --- /dev/null +++ b/weblate/mass-edit.py @@ -0,0 +1,57 @@ +from typing import Dict + +import requests + +from config import * + +s = requests.Session() +s.headers.update({"Authorization": "Token " + token}) + + +def lock_component(component, unlock=False): + lock = not unlock + lock_url = component["lock_url"] + r = s.post(lock_url, data={"lock": lock}) + print(r.json()) + r.raise_for_status() + + +def update_setting(component, settings: Dict): + component_url = component["url"] + r = s.patch(component_url, data=settings) + if r.status_code > 200: + print(r.json()) + r.raise_for_status() + + +components = {} + +r = s.get(url + "projects/matomo/components/") + +data = r.json() +count = data["count"] +for comp in data["results"]: + components[comp["slug"]] = comp + +while data["next"]: + r = s.get(data["next"]) + data = r.json() + for comp in data["results"]: + components[comp["slug"]] = comp + +assert len(components) == count + +phpcomponents = {slug: comp for slug, comp in components.items() if not comp["is_glossary"]} + +community_components = {slug: comp for slug, comp in components.items() if "Community" in comp["name"]} + +official_components = {slug: components[slug] for slug in set(phpcomponents) - set(community_components)} + +for slug, comp in phpcomponents.items(): + print(slug, comp["name"]) + print(comp["check_flags"]) + update_setting(comp, { + "check_flags": "php-format,ignore-optional-plural" + }) + # lock_component(comp) + # print("locked")