From ad3fe462ec045493ba73506acc6e1b82821b356c Mon Sep 17 00:00:00 2001 From: Francesco Lodolo Date: Sun, 22 Jan 2023 19:21:40 +0100 Subject: [PATCH] Extract strings for Focus android, clean up scripts (#1024) * Extract strings for Focus in android-l10n * Composer fixes --- app/classes/Transvision/Project.php | 10 +-- app/classes/Transvision/Utils.php | 2 +- app/models/changelog_data.php | 82 ++++++++++++------------- app/scripts/glossaire.sh | 11 ++-- app/scripts/tmx/tmx_products.py | 75 ++++++++++++---------- app/scripts/tmx/tmx_projectconfig.py | 80 ++++++++++++++++++++---- tests/units/Transvision/ShowResults.php | 4 +- tests/units/Transvision/TMX.php | 4 +- 8 files changed, 168 insertions(+), 100 deletions(-) diff --git a/app/classes/Transvision/Project.php b/app/classes/Transvision/Project.php index d923b3da..42a62633 100644 --- a/app/classes/Transvision/Project.php +++ b/app/classes/Transvision/Project.php @@ -47,7 +47,7 @@ class Project */ 'meta' => true, ], - 'firefox_ios' => [ + 'firefox_ios' => [ 'git_repository' => 'firefoxios-l10n', 'locale_mapping' => [ 'bn-IN' => 'bn', @@ -63,11 +63,11 @@ class Project 'source_type' => 'mixed', 'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'], ], - 'comm_l10n'=> [ + 'comm_l10n' => [ 'source_type' => 'mixed', 'variable_patterns' => ['dtd', 'ftl', 'l10njs', 'printf', 'properties'], ], - 'mozilla_org'=> [ + 'mozilla_org' => [ 'git_repository' => 'www-l10n', 'git_branch' => 'master', 'pontoon_project' => 'mozillaorg', @@ -83,7 +83,7 @@ class Project 'source_type' => 'xml', 'variable_patterns' => ['xml_android'], ], - 'vpn_client' => [ + 'vpn_client' => [ 'git_repository' => 'mozilla-vpn-client-l10n', 'underscore_locales' => true, 'pontoon_project' => 'mozilla-vpn-client', @@ -104,7 +104,7 @@ class Project 'comm_l10n', ], // Products using Git - 'git' => [ + 'git' => [ 'android_l10n', 'firefox_ios', 'mozilla_org', 'vpn_client', ], // Products using free text search on Pontoon diff --git a/app/classes/Transvision/Utils.php b/app/classes/Transvision/Utils.php index 859ea263..d7850fb6 100644 --- a/app/classes/Transvision/Utils.php +++ b/app/classes/Transvision/Utils.php @@ -377,7 +377,7 @@ public static function redYellowGreen($number) */ public static function pluralize($count, $text) { - return $count . (($count == 1) ? (" {$text}") : (" ${text}s")); + return $count . (($count == 1) ? (" {$text}") : (" {$text}s")); } /** diff --git a/app/models/changelog_data.php b/app/models/changelog_data.php index 01f1a247..03e7e6c4 100644 --- a/app/models/changelog_data.php +++ b/app/models/changelog_data.php @@ -70,7 +70,7 @@ */ $changelog = [ - '7.0' => [ + '7.0' => [ [ 'message' => ['Allow searching across all projects'], 'section' => ['end_user'], @@ -128,7 +128,7 @@ 'authors' => ['flod'], ], ], - '6.0' => [ + '6.0' => [ [ 'message' => ['Cross-channel support for Gecko-based products. All channels have been replaced by “Gecko products”. Transvision now pulls source strings from the Gecko strings repository instead of cloning code repositories for each channel, reducing data volume from over 20 GB (more than 400 repositories) to ~2 GB on the server (about 100 repositories).'], 'section' => ['end_user'], @@ -186,7 +186,7 @@ 'authors' => ['tchevalier'], ], ], - '5.2' => [ + '5.2' => [ [ 'message' => ['For locales working on Pootle or Pontoon, added links under Aurora search results to quickly access translations in the tool'], 'section' => ['end_user'], @@ -273,7 +273,7 @@ 'authors' => ['flod'], ], ], - '5.1' => [ + '5.1' => [ [ 'message' => ['New QA view for Empty strings that can be used to identify strings that should have been localized and are empty by mistake, and strings that should actually remain empty.'], 'section' => ['end_user'], @@ -303,7 +303,7 @@ 'authors' => ['flod'], ], ], - '5.0' => [ + '5.0' => [ [ 'message' => ['“To Latin” button added to Serbian results, providing on-the-fly transliteration'], 'section' => ['end_user'], @@ -426,7 +426,7 @@ 'authors' => ['flod'], ], ], - '4.4' => [ + '4.4' => [ [ 'message' => ['Allow toggling all locales checkboxes in the global view for commonly unlocalized words'], 'section' => ['end_user'], @@ -442,7 +442,7 @@ 'authors' => ['pascal'], ], ], - '4.3' => [ + '4.3' => [ [ 'message' => ['Allow filtering by components on Consistency view'], 'section' => ['end_user'], @@ -573,7 +573,7 @@ 'authors' => ['SkySymbol', 'pascal'], ], ], - '4.2' => [ + '4.2' => [ [ 'message' => ['Create view to display translation inconsistencies'], 'section' => ['end_user'], @@ -736,7 +736,7 @@ 'authors' => ['pascal'], ], ], - '4.1' => [ + '4.1' => [ [ 'message' => ['Remove Gaia 2.0, 2.1, 2.2 repositories'], 'section' => ['end_user'], @@ -903,7 +903,7 @@ 'authors' => ['Clement', 'tchevalier'], ], ], - '4.0' => [ + '4.0' => [ [ 'message' => ['Propose search suggestions as you type in the search field'], 'section' => ['end_user'], @@ -1012,7 +1012,7 @@ 'authors' => ['flod'], ], ], - '3.10' => [ + '3.10' => [ [ 'message' => ['Provide a way to go back to the search view from the onestring view'], 'section' => ['end_user'], @@ -1076,7 +1076,7 @@ 'authors' => ['the team'], ], ], - '3.9' => [ + '3.9' => [ [ 'message' => ['Update Transvision for mozilla.org migration to GitHub'], 'section' => ['end_user'], @@ -1168,7 +1168,7 @@ 'authors' => ['flod'], ], ], - '3.8' => [ + '3.8' => [ [ 'message' => ['Add a widget in search form to switch source and target locales'], 'section' => ['end_user'], @@ -1280,7 +1280,7 @@ 'authors' => ['SkySymbol'], ], ], - '3.7' => [ + '3.7' => [ [ 'message' => ['The glossary view looks better and is visually more consistent with the rest of the site'], 'section' => ['end_user'], @@ -1369,7 +1369,7 @@ 'authors' => ['flod'], ], ], - '3.6' => [ + '3.6' => [ [ 'message' => ['Added a new view exposing all strings that are kept identical to en-US'], 'section' => ['end_user'], @@ -1468,7 +1468,7 @@ 'authors' => ['flod'], ], ], - '3.5' => [ + '3.5' => [ [ 'message' => ['Starting with this release, adding a locale to a repository (mostly Gaia) no longer requires releasing a new version of Transvision as the list of locales per repositories is now fetched from a web service maintained by flod, which means that adding new locales to Transvision can now be done at any time'], 'section' => ['end_user'], @@ -1593,7 +1593,7 @@ 'authors' => ['Anthony Maton'], ], ], - '3.4' => [ + '3.4' => [ [ 'message' => ['On demand TMX generation: The static download page for TMX was replaced by a dynamic one in which you can select which repositories you want to use to build the translation memory'], 'section' => ['end_user'], @@ -1654,7 +1654,7 @@ 'authors' => ['team'], ], ], - '3.3' => [ + '3.3' => [ [ 'message' => ['Search hints: If your search for a word or entity yields no result, Transvision proposes similar searches that do yield results'], 'section' => ['end_user'], @@ -1726,7 +1726,7 @@ 'authors' => ['pascal'], ], ], - '3.2' => [ + '3.2' => [ [ 'message' => ['www.mozilla.org support: Transvision can now extract and index projects using the .lang format, the first repository added is www.mozilla.org and appears as a separate channel. Source links and Bugzilla links are adjusted to point to subversion instead of Mercurial and to file bugs in the www.mozilla.org/L10N component instead of the Mozilla Localization one. This makes Transvision more useful for people working on Web localization'], 'section' => ['end_user'], @@ -1754,7 +1754,7 @@ 'authors' => ['pascal'], ], ], - '3.1' => [ + '3.1' => [ [ 'message' => ['Top menu: The application now has a top menu summarizing and categorizing the different views in the application'], 'section' => ['end_user'], @@ -1803,7 +1803,7 @@ 'authors' => ['flod'], ], ], - '3.0' => [ + '3.0' => [ [ 'message' => ['New view: 3 locales search in your strings for potential errors'], 'section' => ['end_user'], @@ -1878,7 +1878,7 @@ 'authors' => ['flod'], ], ], - '2.9' => [ + '2.9' => [ [ 'message' => ['Two new repos are added for searches: Gaia 1.1 and Gaia 1.2'], 'section' => ['end_user'], @@ -1920,7 +1920,7 @@ 'authors' => ['jesus'], ], ], - '2.8' => [ + '2.8' => [ [ 'message' => ['Make search context changes clearer, the type of search (strings, entities, strings & entities) is now displayed as a hint below the search field'], 'section' => ['end_user'], @@ -1958,7 +1958,7 @@ 'authors' => ['flod'], ], ], - '2.7' => [ + '2.7' => [ [ 'message' => ['The repository select box is now located on the far left of the search page. Switching repositories now dynamically updates the select boxes for locales with the right locales'], 'section' => ['end_user'], @@ -2001,7 +2001,7 @@ 'authors' => ['pascal'], ], ], - '2.6' => [ + '2.6' => [ [ 'message' => ['All TMX files for all locales/repos combinations are now available via a TMX download page'], 'section' => ['end_user'], @@ -2024,7 +2024,7 @@ 'authors' => ['jesus'], ], ], - '2.5' => [ + '2.5' => [ [ 'message' => ['Updated visual theme inspired by Mozilla Sandstone, responsive design'], 'section' => ['end_user'], @@ -2056,7 +2056,7 @@ 'section' => ['other'], ], ], - '2.4' => [ + '2.4' => [ [ 'message' => ['There is now a <report a bug> link below each translated string that allows anybody to report a bug in Bugzilla for a badly translated string'], 'section' => ['end_user'], @@ -2064,7 +2064,7 @@ 'authors' => ['jesus', 'pascal'], ], ], - '2.3' => [ + '2.3' => [ [ 'message' => ['You now can remember your locales and repo choices and bypass locale detection with checkboxes, a cookie will be set and remember your preferences'], 'section' => ['end_user'], @@ -2097,7 +2097,7 @@ 'section' => ['other'], ], ], - '2.2' => [ + '2.2' => [ [ 'message' => ['Selected search type value (strings, entities, strings and entities) is kept after a search.'], 'section' => ['end_user'], @@ -2119,7 +2119,7 @@ 'section' => ['end_user'], ], ], - '2.1' => [ + '2.1' => [ [ 'message' => ['New feature: New select box option to search in strings, entities, or both strings and entities.'], 'section' => ['end_user'], @@ -2171,7 +2171,7 @@ 'section' => ['other'], ], ], - '2.0' => [ + '2.0' => [ [ 'message' => ['New feature: In search results, there is now a source link next to the original string and your translation, this links to the file on hg.mozilla.org, this way you can find easily where the file to edit is.'], 'section' => ['end_user'], @@ -2201,7 +2201,7 @@ 'section' => ['other'], ], ], - '1.9' => [ + '1.9' => [ [ 'message' => ['Searches including special characters such as [, (, { are now possible (useful for plurals in Gaia entities, replacement variables in Gais strings or output of messages containing function names in developer tools)'], 'section' => ['end_user'], @@ -2231,7 +2231,7 @@ 'section' => ['other'], ], ], - '1.8' => [ + '1.8' => [ [ 'message' => ['Searches need to be at least 2 characters long, single letter searches now return an error message.'], 'section' => ['end_user'], @@ -2249,7 +2249,7 @@ 'section' => ['other'], ], ], - '1.7' => [ + '1.7' => [ [ 'message' => ['New experimental feature: You can now see all the translated access keys that are potentially wrong for your locale. If you see a reddish square next to your access key letter such as this one :  , it means that there is a space in your string and the access key may not work.'], 'section' => ['end_user'], @@ -2272,7 +2272,7 @@ 'section' => ['developers'], ], ], - '1.6' => [ + '1.6' => [ [ 'message' => ['New experimental feature: You can now compare differences in your translations across channels (central, aurora, beta, release) on this page Channel to Channel differences'], 'section' => ['end_user'], @@ -2299,7 +2299,7 @@ 'section' => ['other'], ], ], - '1.5' => [ + '1.5' => [ [ 'message' => ['New feature: Gaia strings are now included and merged with your repos. You can also do searches for the Gaia repo only'], 'section' => ['end_user'], @@ -2330,7 +2330,7 @@ 'section' => ['other'], ], ], - '1.4' => [ + '1.4' => [ [ 'message' => ['New feature: locale to locale comparison. There is now two locale switchers, the source and the target one. By default, the source is en-US and the target is your detected locale code. You can manually set a different source than en-US so as to compare your translations with another locale. Note that the search results will be limited to the amount of translated strings in the source locale.'], 'section' => ['end_user'], @@ -2349,7 +2349,7 @@ 'section' => ['other'], ], ], - '1.3' => [ + '1.3' => [ [ 'message' => ['Strings in .ini and .inc files are now also in results'], 'section' => ['end_user'], @@ -2375,7 +2375,7 @@ 'section' => ['other'], ], ], - '1.2' => [ + '1.2' => [ [ 'message' => ['Searches for strings with single and double quotes work ex: Search for “Don\'t”'], 'section' => ['end_user'], @@ -2405,7 +2405,7 @@ 'section' => ['other'], ], ], - '1.1' => [ + '1.1' => [ [ 'message' => ['added ach, ff, lij, my, wo locales'], 'section' => ['end_user'], @@ -2443,7 +2443,7 @@ 'section' => ['other'], ], ], - '1.0' => [ + '1.0' => [ [ 'message' => ['Initial import of existing code into github and reinstalling on MozFR server'], 'section' => ['end_user'], diff --git a/app/scripts/glossaire.sh b/app/scripts/glossaire.sh index b99ab952..76d54709 100755 --- a/app/scripts/glossaire.sh +++ b/app/scripts/glossaire.sh @@ -149,7 +149,7 @@ function updateGeckoStrings() { # $1: Locale code echogreen "Create cache for $repo_name/$1" mkdir -p "${root}TMX/${locale}/" - nice -20 python $install/app/scripts/tmx/tmx_products.py $repo_folder/$1/ $1 en-US $repo_name + nice -20 python $install/app/scripts/tmx/tmx_products.py --path $repo_folder/$1/ --locale $1 --ref en-US --repo $repo_name } local repo_name="gecko_strings" @@ -260,7 +260,7 @@ function updateCommL10n() { # $1: Locale code echogreen "Create cache for $repo_name/$1" mkdir -p "${root}TMX/${locale}/" - nice -20 python $install/app/scripts/tmx/tmx_products.py $repo_folder/$1/ $1 en-US $repo_name + nice -20 python $install/app/scripts/tmx/tmx_products.py --path $repo_folder/$1/ --locale $1 --ref en-US --repo $repo_name } local repo_name="comm_l10n" @@ -307,7 +307,8 @@ function updateAndroidl10n() { fi echogreen "Extract strings for android-l10n" cd $install - nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile.toml en-US android_l10n + nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile.toml --ref en-US --repo android_l10n + nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile/focus-android/l10n.toml --ref en-US --repo android_l10n --mode append --prefix mozilla-mobile/focus-android } function updateMozOrg() { @@ -319,8 +320,8 @@ function updateMozOrg() { fi echogreen "Extract strings for mozilla.org (Fluent)" cd $install - nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $mozilla_org/l10n-pontoon.toml en mozilla_org - nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $mozilla_org/l10n-vendor.toml en mozilla_org + nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $mozilla_org/l10n-pontoon.toml --ref en --repo mozilla_org + nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $mozilla_org/l10n-vendor.toml --ref en --repo mozilla_org } echogreen "Activating virtualenv..." diff --git a/app/scripts/tmx/tmx_products.py b/app/scripts/tmx/tmx_products.py index be3eba2c..07095e6f 100755 --- a/app/scripts/tmx/tmx_products.py +++ b/app/scripts/tmx/tmx_products.py @@ -61,13 +61,13 @@ def __init__(self, storage_path, locale, reference_locale, repository_name): # Define the local storage filenames self.storage_file = os.path.join( - storage_path, locale, "cache_{}_{}".format(locale, repository_name) + storage_path, locale, f"cache_{locale}_{repository_name}" ) self.reference_storage_file = os.path.join( storage_path, reference_locale, - "cache_{}_{}".format(reference_locale, repository_name), + f"cache_{reference_locale}_{repository_name}", ) def setRepositoryPath(self, path): @@ -102,7 +102,7 @@ def getRelativePath(self, file_name): relative_path = file_name[len(self.repository_path) + 1 :] # Prepend storage_prefix if defined if self.storage_prefix != "": - relative_path = "{}/{}".format(self.storage_prefix, relative_path) + relative_path = f"{self.storage_prefix}/{relative_path}" return relative_path @@ -112,7 +112,7 @@ def extractStrings(self): # If storage_mode is append, read existing translations (if available) # before overriding them if self.storage_mode == "append": - file_name = "{}.json".format(self.storage_file) + file_name = f"{self.storage_file}.json" if os.path.isfile(file_name): with open(file_name) as f: self.translations = json.load(f) @@ -132,28 +132,24 @@ def extractStrings(self): # Ignore Junk if isinstance(entity, parser.Junk): continue - string_id = "{}:{}".format(self.getRelativePath(file_name), entity) + string_id = f"{self.getRelativePath(file_name)}:{entity}" if file_extension == ".ftl": if entity.raw_val is not None: self.translations[string_id] = entity.raw_val # Store attributes for attribute in entity.attributes: - attr_string_id = "{}:{}.{}".format( - self.getRelativePath(file_name), - entity, - attribute, - ) + attr_string_id = f"{self.getRelativePath(file_name)}:{entity}.{attribute}" self.translations[attr_string_id] = attribute.raw_val else: self.translations[string_id] = entity.raw_val except Exception as e: - print("Error parsing file: {}".format(file_name)) + print(f"Error parsing file: {file_name}") print(e) # Remove extra strings from locale if self.reference_locale != self.locale: # Read the JSON cache for reference locale if available - file_name = "{}.json".format(self.reference_storage_file) + file_name = f"{self.reference_storage_file}.json" if os.path.isfile(file_name): with open(file_name) as f: reference_strings = json.load(f) @@ -173,7 +169,7 @@ def storeTranslations(self, output_format): if output_format != "php": # Store translations in JSON format json_output = json.dumps(self.translations, sort_keys=True) - with open("{}.json".format(self.storage_file), "w") as f: + with open(f"{self.storage_file}.json", "w") as f: f.write(json_output) if output_format != "json": @@ -187,10 +183,10 @@ def storeTranslations(self, output_format): for string_id in string_ids: translation = self.escape(self.translations[string_id]) string_id = self.escape(string_id) - output_php.append("'{}' => '{}',\n".format(string_id, translation)) + output_php.append(f"'{string_id}' => '{translation}',\n") output_php.append("];\n") - file_name = "{}.php".format(self.storage_file) + file_name = f"{self.storage_file}.php" with codecs.open(file_name, "w", encoding="utf-8") as f: f.writelines(output_php) @@ -219,32 +215,50 @@ def escape(self, translation): def main(): # Read command line input parameters parser = argparse.ArgumentParser() - parser.add_argument("repo_path", help="Path to locale files") - parser.add_argument("locale_code", help="Locale language code") - parser.add_argument("reference_code", help="Reference language code") - parser.add_argument("repository_name", help="Repository name") parser.add_argument( - "--output", - nargs="?", - type=str, - choices=["json", "php"], - help="Store only one type of output.", - default="", + "--path", + dest="repo_path", + help="Path to locale files", + required=True, + ) + parser.add_argument( + "--locale", + dest="locale_code", + help="Locale code", + required=True, + ) + parser.add_argument( + "--ref", + dest="reference_code", + help="Reference locale code", + required=True, ) parser.add_argument( - "storage_mode", + "--repo", dest="repository_name", help="Repository name", required=True + ) + parser.add_argument( + "--mode", + dest="storage_mode", nargs="?", - help="If set to 'append', translations will be added to " - "an existing cache file", + help="If set to 'append', translations will be added to an existing cache file", default="", ) parser.add_argument( - "storage_prefix", + "--prefix", + dest="storage_prefix", nargs="?", help="This prefix will be prependended to the identified " "path in string IDs (e.g. extensions/irc for Chatzilla)", default="", ) + parser.add_argument( + "--output", + nargs="?", + type=str, + choices=["json", "php"], + help="Store only one type of output.", + default="", + ) args = parser.parse_args() extracted_strings = StringExtraction( @@ -252,8 +266,7 @@ def main(): ) extracted_strings.setRepositoryPath(args.repo_path) - if args.storage_mode == "append": - extracted_strings.setStorageMode("append", args.storage_prefix) + extracted_strings.setStorageMode("append", args.storage_prefix) extracted_strings.extractStrings() extracted_strings.storeTranslations(args.output) diff --git a/app/scripts/tmx/tmx_projectconfig.py b/app/scripts/tmx/tmx_projectconfig.py index ca9dc84b..ff3381e5 100755 --- a/app/scripts/tmx/tmx_projectconfig.py +++ b/app/scripts/tmx/tmx_projectconfig.py @@ -44,6 +44,8 @@ def __init__(self, toml_path, storage_path, reference_locale, repository_name): # Set defaults self.translations = {} + self.storage_mode = "" + self.storage_prefix = "" # Set instance variables self.toml_path = toml_path @@ -51,6 +53,13 @@ def __init__(self, toml_path, storage_path, reference_locale, repository_name): self.reference_locale = reference_locale self.repository_name = repository_name + def setStorageMode(self, mode, prefix): + """Set storage mode and prefix.""" + + self.storage_mode = mode + # Strip trailing '/' from storage_prefix + self.storage_prefix = prefix.rstrip(os.path.sep) + def extractStrings(self): """Extract strings from all locales.""" @@ -59,10 +68,27 @@ def extractStrings(self): basedir = os.path.join(basedir, project_config.root) reference_cache = {} - self.translations[self.reference_locale] = {} + + if self.reference_locale not in self.translations: + self.translations[self.reference_locale] = {} for locale in project_config.all_locales: + + # If storage_mode is append, read existing translations (if available) + if self.storage_mode == "append": + storage_file = os.path.join( + os.path.join(self.storage_path, locale), + f"cache_{locale}_{self.repository_name}", + ) + file_name = f"{storage_file}.json" + if os.path.isfile(file_name): + with open(file_name) as f: + tmp_translations = json.load(f) + f.close() + self.translations[locale] = tmp_translations + else: + self.translations[locale] = {} + files = paths.ProjectFiles(locale, [project_config]) - self.translations[locale] = {} for l10n_file, reference_file, _, _ in files: if not os.path.exists(l10n_file): # File not available in localization @@ -73,6 +99,9 @@ def extractStrings(self): continue key_path = os.path.relpath(reference_file, basedir) + # Prepend storage_prefix if defined + if self.storage_prefix != "": + key_path = f"{self.storage_prefix}/{key_path}" try: p = getParser(reference_file) except UserWarning: @@ -82,9 +111,7 @@ def extractStrings(self): reference_cache[key_path] = set(p.parse().keys()) self.translations[self.reference_locale].update( ( - "{}/{}:{}".format( - self.repository_name, key_path, entity.key - ), + f"{self.repository_name}/{key_path}:{entity.key}", entity.raw_val, ) for entity in p.parse() @@ -93,7 +120,7 @@ def extractStrings(self): p.readFile(l10n_file) self.translations[locale].update( ( - "{}/{}:{}".format(self.repository_name, key_path, entity.key), + f"{self.repository_name}/{key_path}:{entity.key}", entity.raw_val, ) for entity in p.parse() @@ -110,7 +137,7 @@ def storeTranslations(self, output_format): translations = self.translations[locale] storage_folder = os.path.join(self.storage_path, locale) storage_file = os.path.join( - storage_folder, "cache_{}_{}".format(locale, self.repository_name) + storage_folder, f"cache_{locale}_{self.repository_name}" ) # Make sure that the TMX folder exists @@ -120,7 +147,7 @@ def storeTranslations(self, output_format): if output_format != "php": # Store translations in JSON format json_output = json.dumps(translations, sort_keys=True) - with open("{}.json".format(storage_file), "w") as f: + with open(f"{storage_file}.json", "w") as f: f.write(json_output) if output_format != "json": @@ -134,10 +161,10 @@ def storeTranslations(self, output_format): for string_id in string_ids: translation = self.escape(translations[string_id]) string_id = self.escape(string_id) - output_php.append("'{}' => '{}',\n".format(string_id, translation)) + output_php.append(f"'{string_id}' => '{translation}',\n") output_php.append("];\n") - file_name = "{}.php".format(storage_file) + file_name = f"{storage_file}.php" with codecs.open(file_name, "w", encoding="utf-8") as f: f.writelines(output_php) @@ -167,8 +194,30 @@ def main(): # Read command line input parameters parser = argparse.ArgumentParser() parser.add_argument("toml_path", help="Path to root l10n.toml file") - parser.add_argument("reference_code", help="Reference language code") - parser.add_argument("repository_name", help="Repository name") + parser.add_argument( + "--ref", + dest="reference_code", + help="Reference language code", + required=True, + ) + parser.add_argument( + "--repo", dest="repository_name", help="Repository name", required=True + ) + parser.add_argument( + "--mode", + dest="storage_mode", + nargs="?", + help="If set to 'append', translations will be added to an existing cache file", + default="", + ) + parser.add_argument( + "--prefix", + dest="storage_prefix", + nargs="?", + help="This prefix will be prependended to the identified " + "path in string IDs (e.g. extensions/irc for Chatzilla)", + default="", + ) parser.add_argument( "--output", nargs="?", @@ -180,8 +229,13 @@ def main(): args = parser.parse_args() extracted_strings = StringExtraction( - args.toml_path, storage_path, args.reference_code, args.repository_name + args.toml_path, + storage_path, + args.reference_code, + args.repository_name, ) + extracted_strings.setStorageMode(args.storage_mode, args.storage_prefix) + extracted_strings.extractStrings() extracted_strings.storeTranslations(args.output) diff --git a/tests/units/Transvision/ShowResults.php b/tests/units/Transvision/ShowResults.php index 9c9af23d..37985eec 100644 --- a/tests/units/Transvision/ShowResults.php +++ b/tests/units/Transvision/ShowResults.php @@ -248,14 +248,14 @@ public function getRepositorySearchResultsDP() 0 => [ 'apps/system/system.properties:softwareHomeButton.ariaLabel' => 'Home', 'browser/chrome/browser/safebrowsing/phishing-afterload-warning-message.dtd:safeb.blocked.malwarePage.longDesc' - => '<p>Attack pages try to install programs that steal private information, use your computer to ' + => '<p>Attack pages try to install programs that steal private information, use your computer to ' . 'attack others, or damage your system.</p><p>Some attack pages intentionally distribute ' . 'harmful software, but many are compromised without the knowledge or permission of their owners.</p>', ], 1 => [ 'apps/system/system.properties:softwareHomeButton.ariaLabel' => 'Home', 'browser/chrome/browser/safebrowsing/phishing-afterload-warning-message.dtd:safeb.blocked.malwarePage.longDesc' - => '<p>Les pages malveillantes essaient d'installer des programmes qui volent des informations ' + => '<p>Les pages malveillantes essaient d'installer des programmes qui volent des informations ' . ' personnelles, qui utilisent votre ordinateur pour en attaquer d'autres ou qui endommagent votre ' . 'système.</p><p>Certaines pages distribuent intentionnellement des logiciels malfaisants, ' . 'mais beaucoup sont compromises sans la permission de leurs propriétaires ou sans qu'ils en aient ' diff --git a/tests/units/Transvision/TMX.php b/tests/units/Transvision/TMX.php index fa0657c6..34ddc8b7 100644 --- a/tests/units/Transvision/TMX.php +++ b/tests/units/Transvision/TMX.php @@ -13,7 +13,7 @@ public function createDP() return [ [ [ - 'fr' => [ + 'fr' => [ 'shared/date/date.properties:month-7-genitive' => 'août', 'shared/download/download.properties:unsupported_file_type_download_title' => 'Ouverture impossible', ], @@ -59,7 +59,7 @@ public function createOmegatDP() return [ [ [ - 'fr' => [ + 'fr' => [ 'shared/date/date.properties:month-7-genitive' => 'août', 'shared/download/download.properties:unsupported_file_type_download_title' => 'Ouverture impossible', ],