Last active
May 9, 2022 13:13
-
-
Save flodolo/e157bf85dec9697ed8ffbc0a3fa1f615 to your computer and use it in GitHub Desktop.
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(): | |
query = """ | |
{ | |
firefox: project(slug: "firefox") { | |
...allLocales | |
} | |
firefox_ios: project(slug: "firefox-for-ios") { | |
...allLocales | |
} | |
android_l10n_fenix: project(slug: "firefox-for-android") { | |
...allLocales | |
} | |
} | |
fragment allLocales on Project { | |
localizations { | |
locale { | |
code | |
} | |
} | |
} | |
""" | |
locales = [] | |
try: | |
url = "https://pontoon.mozilla.org/graphql?query={}".format(urlquote(query)) | |
print("Reading sources for Pontoon") | |
response = urlopen(url) | |
json_data = json.load(response) | |
for project, project_data in json_data["data"].items(): | |
for element in project_data["localizations"]: | |
locales.append(element["locale"]["code"]) | |
# Remove duplicates | |
locales = list(set(locales)) | |
locales.sort() | |
print(f"Locales ({len(locales)}):" ) | |
print("[", end="") | |
for l in locales: | |
print(f"'{l}', ", end="") | |
print("]\n\n") | |
print(", ".join(locales)) | |
except Exception as e: | |
print(e) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment