Pier Angelo Vendrame pushed to branch tor-browser-115.4.0esr-13.5-1 at The Tor Project / Applications / Tor Browser

Commits:

1 changed file:

Changes:

  • tools/torbrowser/migrate_l10n.py
    ... ... @@ -103,10 +103,10 @@ class WeblateMetadata:
    103 103
             # Expect the final structure to be:
    
    104 104
             # {
    
    105 105
             #   template: {
    
    106
    -        #     "component-name": str,       # Used for API translations query.
    
    106
    +        #     "translations-url": str,     # Used for API translations query.
    
    107 107
             #     "translations": {
    
    108 108
             #        filename: {
    
    109
    -        #          "language-code": str,   # Used for API units query.
    
    109
    +        #          "units-url": str,       # Used for API units query.
    
    110 110
             #          "units": {
    
    111 111
             #            context: {
    
    112 112
             #              "translated": bool,
    
    ... ... @@ -130,9 +130,8 @@ class WeblateMetadata:
    130 130
             with urllib.request.urlopen(weblate_request, timeout=20) as response:
    
    131 131
                 return json.load(response)
    
    132 132
     
    
    133
    -    def _get_from_weblate(self, request):
    
    133
    +    def _get_from_weblate(self, url):
    
    134 134
             ret = []
    
    135
    -        url = "https://hosted.weblate.org/api/" + request
    
    136 135
             while url:
    
    137 136
                 response = self._get_weblate_response(url)
    
    138 137
                 # Continue to fetch the next page, if it is present.
    
    ... ... @@ -146,10 +145,12 @@ class WeblateMetadata:
    146 145
             if self._components is None:
    
    147 146
                 self._components = {
    
    148 147
                     comp["template"]: {
    
    149
    -                    "name": comp["slug"],
    
    150 148
                         "translations": None,
    
    149
    +                    "translations-url": comp["translations_url"],
    
    151 150
                     }
    
    152
    -                for comp in self._get_from_weblate("projects/tor/components/")
    
    151
    +                for comp in self._get_from_weblate(
    
    152
    +                    "https://hosted.weblate.org/api/projects/tor/components/"
    
    153
    +                )
    
    153 154
                     if comp["template"]
    
    154 155
                 }
    
    155 156
             return self._components
    
    ... ... @@ -160,16 +161,12 @@ class WeblateMetadata:
    160 161
                 self.logger.warning(f"No component in weblate for {template}.")
    
    161 162
                 return None
    
    162 163
             if component["translations"] is None:
    
    163
    -            comp_name = component["name"]
    
    164 164
                 component["translations"] = {
    
    165 165
                     trans["filename"]: {
    
    166
    -                    "component-name": comp_name,
    
    167
    -                    "language-code": trans["language"]["code"],
    
    168 166
                         "units": None,
    
    167
    +                    "units-url": trans["units_list_url"],
    
    169 168
                     }
    
    170
    -                for trans in self._get_from_weblate(
    
    171
    -                    f"components/tor/{comp_name}/translations/"
    
    172
    -                )
    
    169
    +                for trans in self._get_from_weblate(component["translations-url"])
    
    173 170
                 }
    
    174 171
             return component["translations"]
    
    175 172
     
    
    ... ... @@ -182,15 +179,11 @@ class WeblateMetadata:
    182 179
                 self.logger.warning(f"No translation in weblate for {file}.")
    
    183 180
                 return None
    
    184 181
             if translation["units"] is None:
    
    185
    -            comp_name = translation["component-name"]
    
    186
    -            lang_code = translation["language-code"]
    
    187 182
                 translation["units"] = {
    
    188 183
                     unit["context"]: {
    
    189 184
                         "translated": unit["translated"],
    
    190 185
                     }
    
    191
    -                for unit in self._get_from_weblate(
    
    192
    -                    f"translations/tor/{comp_name}/{lang_code}/units/"
    
    193
    -                )
    
    186
    +                for unit in self._get_from_weblate(translation["units-url"])
    
    194 187
                 }
    
    195 188
             return translation["units"]
    
    196 189