Skip to content

Instantly share code, notes, and snippets.

@flodolo
Last active August 18, 2022 14:36
Show Gist options
  • Save flodolo/d53726d21fbe4efc6b8ea9c453059b23 to your computer and use it in GitHub Desktop.
Save flodolo/d53726d21fbe4efc6b8ea9c453059b23 to your computer and use it in GitHub Desktop.
Extract shipping locales for Firefox/Focus mobile and VPN
#! /usr/bin/env python3
"""
Check if Pontoon locales are missing in the repository for iOS projects.
"""
import argparse
import json
import sys
from urllib.parse import quote as urlquote
from urllib.request import urlopen
def getPontoonLocales(project_slug, threshold):
query = f"""
{{
project: project(slug: "{project_slug}") {{
localizations {{
locale {{
code
}},
missingStrings,
totalStrings
}}
}}
}}
"""
url = f"https://pontoon.mozilla.org/graphql?query={urlquote(query)}"
try:
response = urlopen(url)
json_data = json.load(response)
if "errors" in json_data:
sys.exit(f"Project {project_slug} not found in Pontoon.")
locale_list = []
for e in json_data["data"]["project"]["localizations"]:
completion = (e["totalStrings"] - e["missingStrings"]) / e["totalStrings"] * 100
if completion > threshold:
locale_list.append(e["locale"]["code"])
locale_list.sort()
return locale_list
except Exception as e:
sys.exit(e)
def main():
# Pontoon data
config = {
"firefox-ios": {
"name": "Firefox for iOS",
"pontoon_slug": "firefox-for-ios",
"threshold": 0,
},
"focus-ios": {
"name": "Focus for iOS",
"pontoon_slug": "focus-for-ios",
"threshold": 0,
},
"firefox-android": {
"name": "Firefox for Android",
"pontoon_slug": "focus-for-android",
"threshold": 0,
},
"focus-android": {
"name": "Focus for Android",
"pontoon_slug": "focus-for-android",
"threshold": 0,
},
"vpn-client": {
"name": "Mozilla VPN Client",
"pontoon_slug": "mozilla-vpn-client",
"threshold": 70,
},
"fxa": {
"name": "Firefox Accounts",
},
"firefox": {
"name": "Firefox Desktop",
},
}
locales = {}
for p, project in config.items():
if "pontoon_slug" not in project:
continue
pontoon_locales = getPontoonLocales(project["pontoon_slug"], project["threshold"])
pontoon_locales.sort()
for loc in pontoon_locales:
if loc not in locales:
locales[loc] = {}
locales[loc][p] = "x"
# Firefox Accounts
url = "https://raw.githubusercontent.com/mozilla/fxa/main/packages/fxa-shared/l10n/supportedLanguages.json"
try:
response = urlopen(url)
fxa_locales = json.load(response)
extra_locales = ["en", "fy", "pt", "sv"]
fxa_locales = list(set(fxa_locales) - set(extra_locales))
fxa_locales.sort()
for loc in fxa_locales:
if loc not in locales:
locales[loc] = {}
locales[loc]["fxa"] = "x"
except Exception as e:
sys.exit(e)
# Firefox
url = "https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/shipped-locales"
try:
response = urlopen(url)
fx_locales = []
for loc in response:
fx_locales.append(loc.rstrip().decode())
fx_locales.sort()
fx_locales.remove("ja-JP-mac")
for loc in fx_locales:
if loc not in locales:
locales[loc] = {}
locales[loc]["firefox"] = "x"
except Exception as e:
sys.exit(e)
products = list(config.keys())
products.sort()
header = "Locale,"
for p in products:
header += f"{config[p]['name']},"
body = []
loc_list = list(locales.keys())
loc_list.sort()
for loc in loc_list:
row = f"{loc},"
for p in products:
if p in locales[loc]:
row += "x,"
else:
row += ","
body.append(row[:-1])
output = [header[:-1]] + body
print("\n".join(output))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment