Created
March 29, 2025 13:53
-
-
Save flodolo/f41e0d7073df458a7fb30a854d0da126 to your computer and use it in GitHub Desktop.
Check monitor prod locales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
from urllib.parse import quote as urlquote | |
from urllib.request import urlopen | |
def main(): | |
# Get completion stats for locales from Pontoon | |
query = """ | |
{ | |
firefox: project(slug: "firefox-monitor-website") { | |
localizations { | |
locale { | |
code | |
}, | |
missingStrings, | |
pretranslatedStrings, | |
totalStrings | |
} | |
} | |
} | |
""" | |
pontoon_stats = {} | |
try: | |
print("Reading Pontoon stats...") | |
url = f"https://pontoon.mozilla.org/graphql?query={urlquote(query)}&raw" | |
response = urlopen(url) | |
json_data = json.load(response) | |
for project_data in json_data["data"].values(): | |
for element in project_data["localizations"]: | |
locale = element["locale"]["code"] | |
# Don't count pretranslated strings | |
translated = ( | |
element["totalStrings"] | |
- element["missingStrings"] | |
- element["pretranslatedStrings"] | |
) | |
pontoon_stats[locale] = round( | |
(float(translated)) / element["totalStrings"] * 100, | |
2, | |
) | |
except Exception as e: | |
print(e) | |
try: | |
print("Reading production locales from .env") | |
prod_config = ( | |
"https://raw.githubusercontent.com/mozilla/blurts-server/main/.env" | |
) | |
response = urlopen(prod_config).read().decode("utf-8") | |
for line in response.splitlines(): | |
if line.startswith("SUPPORTED_LOCALES"): | |
monitor_locales = line.split("=")[1].split(",") | |
except Exception as e: | |
print(e) | |
threshold = 70 | |
below_threshold = [] | |
missing = [] | |
completion_levels = {} | |
for locale, completion in pontoon_stats.items(): | |
c = int(completion) | |
if c not in completion_levels: | |
completion_levels[c] = [locale] | |
else: | |
completion_levels[c].append(locale) | |
if locale not in monitor_locales: | |
if completion > threshold: | |
missing.append(locale) | |
else: | |
if completion < threshold: | |
below_threshold.append(locale) | |
missing.sort() | |
below_threshold.sort() | |
if below_threshold: | |
print( | |
"\nLocales below {}% threshold ({}):".format( | |
threshold, len(below_threshold) | |
) | |
) | |
for locale in below_threshold: | |
print("{} ({}%)".format(locale, pontoon_stats[locale])) | |
else: | |
print( | |
"\nNo locales below {}% threshold ({}).".format( | |
threshold, len(below_threshold) | |
) | |
) | |
if missing: | |
print("\nLocales missing from production ({}):".format(len(missing))) | |
for locale in missing: | |
print("{} ({}%)".format(locale, pontoon_stats[locale])) | |
else: | |
print("\nNo locales missing from production.") | |
print("\n\nCompletion levels:") | |
for c in sorted(completion_levels, reverse=True): | |
locales = completion_levels[c] | |
locales.sort() | |
num = f"({len(locales)} locale" | |
num += ")" if len(locales) == 1 else "s)" | |
print(f"- {c}% {num}: {', '.join(locales)}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment