Skip to content

Instantly share code, notes, and snippets.

@flodolo
Created May 17, 2022 09:11
Show Gist options
  • Save flodolo/291541105f63f90b8d167d14464c4727 to your computer and use it in GitHub Desktop.
Save flodolo/291541105f63f90b8d167d14464c4727 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import json
import os
from urllib.parse import quote as urlquote
from urllib.request import urlopen
query = """
{
vpn_client: project(slug: "firefox-accounts") {
...allLocales
}
}
fragment allLocales on Project {
localizations {
locale {
code
},
totalStrings,
missingStrings
}
}
"""
try:
url = f"https://pontoon.mozilla.org/graphql?query={urlquote(query)}"
print("Reading sources for Pontoon")
response = urlopen(url)
json_data = json.load(response)
pontoon_data = {}
for project, project_data in json_data["data"].items():
for element in project_data["localizations"]:
code = element["locale"]["code"]
pontoon_data[code] = round(
(element["missingStrings"] / element["totalStrings"]) * 100, 2
)
pontoon_locales = list(pontoon_data.keys())
pontoon_locales.sort()
repo_url = (
"https://api.github.com/repos/mozilla/fxa-content-server-l10n/contents/locale"
)
response = urlopen(repo_url)
print("Reading folders in repo")
json_data = json.load(response)
ignored_locales = [
"en",
"en_US",
"fy",
"hi",
"pt",
"sr_Latn",
"sv",
"templates",
]
repo_locales = [
e["name"].replace("_", "-")
for e in json_data
if e["type"] == "dir" and e["name"] not in ignored_locales
]
repo_locales.sort()
missing_pontoon = list(set(repo_locales) - set(pontoon_locales))
if missing_pontoon != [""]:
missing_pontoon.sort()
print("\nList of locales in repository missing from Pontoon project:")
for l in missing_pontoon:
print(f"* {l}")
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment