def main(): parser = argparse.ArgumentParser() parser.add_argument('repo_path', help='Path to locale files') args = parser.parse_args() CheckStrings( os.path.abspath(os.path.dirname(__file__)), args.repo_path)
def main(): script_path = os.path.abspath(os.path.dirname(__file__)) config_file = os.path.join(script_path, os.pardir, "config", "config.ini") if not os.path.isfile(config_file): sys.exit("Missing configuration file.") config = configparser.ConfigParser() config.read(config_file) repo_path = config["default"]["repo_path"] if not os.path.isdir(repo_path): sys.exit("Path to repository in config file is not a directory.") parser = argparse.ArgumentParser() parser.add_argument("--verbose", action="store_true", help="Verbose output (e.g. tokens") args = parser.parse_args() CheckStrings(script_path, repo_path, args.verbose)
def main(): # Read command line input parameters parser = argparse.ArgumentParser() parser.add_argument("locales_path", help="Path to locales folder in local repository") parser.add_argument("--reference", help="Reference locale", action="store", default="en-US") parser.add_argument("--locale", help="Only check a specific locale code", action="store", default="") args = parser.parse_args() extracted_strings = StringExtraction(args.locales_path, args.reference, args.locale) extracted_strings.extractStrings() extracted_strings.checkFTL()
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='') parser.add_argument( 'storage_mode', nargs='?', help= 'If set to \'append\', translations will be added to an existing cache file', default='') parser.add_argument( 'storage_prefix', nargs='?', help= 'This prefix will be prependended to the identified path in string IDs (e.g. extensions/irc for Chatzilla)', default='') args = parser.parse_args() extracted_strings = StringExtraction(storage_path, args.locale_code, args.reference_code, args.repository_name) extracted_strings.setRepositoryPath(args.repo_path) if args.storage_mode == 'append': extracted_strings.setStorageMode('append', args.storage_prefix) extracted_strings.extractStrings() extracted_strings.storeTranslations(args.output)
def main(): parser = argparse.ArgumentParser() parser.add_argument("locale", help="Locale language code") parser.add_argument( "--start", help= "Changeset used as starting point for the diff (default is the changeset shipping in release", ) parser.add_argument( "--end", help= "Changeset used as ending point for the diff (default is tip of the repository", ) args = parser.parse_args() locale = args.locale repository_path = f"/Users/flodolo/mozilla/mercurial/l10n_clones/locales/{locale}/" if args.start: starting_changeset = args.start else: # Get the latest changeset shipping in release url = "https://hg.mozilla.org/releases/mozilla-release/raw-file/default/browser/locales/l10n-changesets.json" l10n_changesets = {} try: print("Reading l10n-changesets.json...") response = urlopen(url) json_data = json.load(response) if not locale in json_data: sys.exit( f"Locale {locale} not available in l10n-changesets.json") else: starting_changeset = json_data[locale]["revision"] except Exception as e: print(e) # Pull latest changes in the repository print("Updating repository...") subprocess.run(["hg", "-R", repository_path, "pull", "-u"]) if args.end: ending_changeset = args.end else: # Get the long hash of the current tip ending_changeset = subprocess.check_output( ["hg", "-R", repository_path, "--debug", "id", "-i"]) ending_changeset = ending_changeset.strip().decode("utf-8") # Update to old revision print(f"Updating repository to revision {starting_changeset}...") subprocess.run( ["hg", "-R", repository_path, "update", "-r", starting_changeset]) # Generate file list and read the content print("Extracting strings...") old_file_list = extractFileList(repository_path) old_strings = extractStrings(old_file_list, repository_path) # Restore repository print(f"Updating repository to revision {ending_changeset}...") subprocess.run(["hg", "-R", repository_path, "update"]) # Generate file list and read the content print("Extracting strings...") new_file_list = extractFileList(repository_path) new_strings = extractStrings(new_file_list, repository_path) # Restore to default print("Restoring repository to default...") subprocess.run(["hg", "-R", repository_path, "pull", "-u"]) output = [] dmp = dmp_module.diff_match_patch() for message_id, message in new_strings.items(): if message_id not in old_strings: old_message = "" else: old_message = old_strings[message_id] if old_message == message: continue diff = dmp.diff_main(old_message, message) dmp.diff_cleanupSemantic(diff) output_element = """ <tr> <td>{}</td> <td>{}</td> </tr>""".format(message_id, dmp.diff_prettyHtml(diff)) output.append(output_element) print("Saving diff to output.html") output_file = [] with open("template.html", "r") as f: for line in f: if "%%BODY%%" in line: output_file.append("\n".join(output)) continue if "%%LOCALE%%" in line: line = line.replace("%%LOCALE%%", locale) if "%%START_CHANGESET%%" in line: line = line.replace("%%START_CHANGESET%%", starting_changeset) if "%%END_CHANGESET%%" in line: line = line.replace("%%END_CHANGESET%%", ending_changeset) output_file.append(line) with open("output.html", "w") as f: f.writelines(output_file) subprocess.run(["open", "output.html"])
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="", ) parser.add_argument( "storage_mode", nargs="?", help="If set to 'append', translations will be added to " "an existing cache file", default="", ) parser.add_argument( "storage_prefix", nargs="?", help="This prefix will be prependended to the identified " "path in string IDs (e.g. extensions/irc for Chatzilla)", default="", ) args = parser.parse_args() extracted_strings = StringExtraction( storage_path, args.locale_code, args.reference_code, args.repository_name ) extracted_strings.setRepositoryPath(args.repo_path) if args.storage_mode == "append": extracted_strings.setStorageMode("append", args.storage_prefix) extracted_strings.extractStrings() extracted_strings.storeTranslations(args.output)
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='') parser.add_argument('storage_mode', nargs='?', help='If set to \'append\', translations will be added to an existing cache file', default='') parser.add_argument('storage_prefix', nargs='?', help='This prefix will be prependended to the identified path in string IDs (e.g. extensions/irc for Chatzilla)', default='') args = parser.parse_args() extracted_strings = StringExtraction( storage_path, args.locale_code, args.reference_code, args.repository_name) extracted_strings.setRepositoryPath(args.repo_path.rstrip('/')) if args.storage_mode == 'append': extracted_strings.setStorageMode('append', args.storage_prefix) extracted_strings.extractStrings() extracted_strings.storeTranslations(args.output)