Bug 1278104 - Create a library to manage translation of Google play descriptions draft
authorSylvestre Ledru <sledru@mozilla.com>
Mon, 13 Jun 2016 16:40:30 +0100
changeset 377882 690007c48c719ee3177ed9b03fb1d5f1635c24eb
parent 377881 dc6b1d9499a8a020686baaabdbd5dd1486568dad
child 377883 320794e3df93091012d2e0f029db569fd32c895d
child 377886 b50a7856839c72ad7321e2b8b28d771822679e2f
push id20883
push usersledru@mozilla.com
push dateMon, 13 Jun 2016 15:49:23 +0000
bugs1278104
milestone49.0a1
Bug 1278104 - Create a library to manage translation of Google play descriptions MozReview-Commit-ID: 4iOffPOGJlW
testing/mozharness/mozharness/mozilla/storel10n.py
new file mode 100644
--- /dev/null
+++ b/testing/mozharness/mozharness/mozilla/storel10n.py
@@ -0,0 +1,48 @@
+""" storel10n.py
+
+    Manage the localization of the Google play store
+
+"""
+
+from mozharness.base.log import LogMixin
+from mozharness.base.script import ScriptMixin
+
+
+class storel10n(ScriptMixin, LogMixin):
+
+    l10n_api_url = "https://l10n.mozilla-community.org/stores_l10n/"
+    all_locales_url = l10n_api_url + "api/google/listing/{channel}/"
+    locale_url = l10n_api_url + "api/google/translation/{channel}/{locale}/"
+    mapping_url = l10n_api_url + "api/google/localesmapping/?reverse"
+
+    def __init__(self, config, log):
+        self.config = config
+        self.log_obj = log
+        self.mappings = []
+
+    def get_list_locales(self, package_name):
+
+        """ Get all the translated locales supported by Google play
+        So, locale unsupported by Google play won't be downloaded
+        Idem for not translated locale
+        """
+        return self.load_json_url(self.all_locales_url.format(channel=package_name))
+
+    def get_translation(self, package_name, locale):
+        """ Get the translation for a locale
+        """
+        return self.load_json_url(self.locale_url.format(channel=package_name, locale=locale))
+
+    def load_mapping(self):
+        """ Download and load the locale mapping
+        """
+        self.mappings = self.load_json_url(self.mapping_url)
+
+    def locale_mapping(self, locale):
+        """ Google play and Mozilla don't have the exact locale code
+        Translate them
+        """
+        if locale in self.mappings:
+            return self.mappings[locale]
+        else:
+            return locale