Created
March 26, 2021 05:03
-
-
Save flodolo/f42d1c563d4d031a738b53deb332c3b6 to your computer and use it in GitHub Desktop.
Multimedia Tabs Strings MR1
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 | |
import os | |
import sys | |
from urllib.request import urlopen | |
def getShippingLocales(): | |
# Get the list of locales shipping in Firefox | |
base = "https://hg.mozilla.org/mozilla-central/raw-file/default/{}" | |
locales_urls = [ | |
base.format("browser/locales/all-locales"), | |
] | |
shipping_locales = [] | |
for locales_url in locales_urls: | |
try: | |
with urlopen(locales_url) as response: | |
output = response.readlines() | |
for locale in output: | |
locale = locale.rstrip().decode() | |
shipping_locales.append(locale) | |
except Exception as e: | |
print(e) | |
shipping_locales = list(set(shipping_locales)) | |
if "en-US" not in shipping_locales: | |
shipping_locales.append("en-US") | |
shipping_locales.sort() | |
return shipping_locales | |
def main(): | |
# Get the list of supported locales in Firefox and Firefox for Android | |
shipping_locales = getShippingLocales() | |
# Path to this script and node modules | |
script_folder = os.path.abspath(os.path.dirname(__file__)) | |
entities = [ | |
"browser/browser/browser.ftl:browser-tab-audio-blocked", | |
"browser/browser/browser.ftl:browser-tab-audio-muted2", | |
"browser/browser/browser.ftl:browser-tab-audio-pip", | |
"browser/browser/browser.ftl:browser-tab-audio-playing2", | |
] | |
transvision_api = "https://transvision.flod.org/api/v1/entity/gecko_strings/?id={}" | |
translations = {} | |
for locale in shipping_locales: | |
translations[locale] = [""] * len(entities) | |
for counter, entity in enumerate(entities): | |
try: | |
url = transvision_api.format(entity) | |
with urlopen(url) as response: | |
json_data = json.load(response) | |
for locale in json_data: | |
translations[locale][counter] = json_data[locale] | |
except Exception as e: | |
print("Error retrieving translations for {}".format(locale)) | |
print(url) | |
print(e) | |
output = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Locale Comparison</title> | |
<meta charSet="utf-8" /> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> | |
<style> | |
body { | |
font-size: 12px; | |
} | |
td.translation { | |
font-size: 8.25px; | |
} | |
td.rtl { | |
text-align: right; | |
} | |
</style> | |
</head> | |
""" | |
output += f""" | |
<body> | |
<div class="container"> | |
<table class="table table-striped table-bordered table-sm"> | |
<thead class="thead-dark"> | |
<tr style="text-align: center"> | |
<th>Locale</th> | |
<th>{translations["en-US"][0]}</th> | |
<th>{translations["en-US"][1]}</th> | |
<th>{translations["en-US"][2]}</th> | |
<th>{translations["en-US"][3]}</th> | |
</tr> | |
</thead> | |
<tbody> | |
""" | |
for locale, locale_translations in translations.items(): | |
direction = " rtl" if locale in ["ar", "he", "fa"] else "" | |
output += f""" | |
<tr> | |
<td>{locale}</td> | |
<td class="translation{direction}">{locale_translations[0]}</td> | |
<td class="translation{direction}">{locale_translations[1]}</td> | |
<td class="translation{direction}">{locale_translations[2]}</td> | |
<td class="translation{direction}">{locale_translations[3]}</td> | |
</tr> | |
""" | |
output += """ | |
</tbody> | |
</table> | |
</div> | |
</body> | |
</html> | |
""" | |
with open("mr1_tabs_l10n.html", "w") as f: | |
f.write(output) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment