fix: add new flag to print string issues explicitly

pull/3205/head
Ryan Miller 7 months ago
parent 3204211dbe
commit 82261d6e7c
No known key found for this signature in database
GPG Key ID: 128C6E0A1246C6B3

@ -4,7 +4,6 @@ import json
import os import os
import sys import sys
# This allows for importing from the localization and util directories NOTE: Auto importing tools will also prepend the import paths with "tools." this will not work and needs to be removed from import paths # This allows for importing from the localization and util directories NOTE: Auto importing tools will also prepend the import paths with "tools." this will not work and needs to be removed from import paths
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
@ -22,7 +21,6 @@ from localization.localeTypes import generateLocalesType
from util.logger import console from util.logger import console
from util.fileUtils import createMappedJsonFileDictionary, writeFile from util.fileUtils import createMappedJsonFileDictionary, writeFile
# If the --throw-error-on-missing flag is passed, the script will exit with an error if there are any missing keys or dynamic variables # If the --throw-error-on-missing flag is passed, the script will exit with an error if there are any missing keys or dynamic variables
# This is useful for CI/CD pipelines to ensure that all translations are consistent # This is useful for CI/CD pipelines to ensure that all translations are consistent
parser = argparse.ArgumentParser(description="Generate locale files") parser = argparse.ArgumentParser(description="Generate locale files")
@ -41,6 +39,11 @@ parser.add_argument(
action="store_true", action="store_true",
help="Print the problems table", help="Print the problems table",
) )
parser.add_argument(
"--print-problem-strings",
action="store_true",
help="Print the problem strings and which locales they are in",
)
parser.add_argument( parser.add_argument(
"--write-problems", action="store_true", help="Write the problems to a file" "--write-problems", action="store_true", help="Write the problems to a file"
) )
@ -109,10 +112,8 @@ for locale, data in locales.items():
localeVariablesOld[locale], localeVariablesOld[locale],
) = extractVariablesFromDict(data) ) = extractVariablesFromDict(data)
problems = identifyLocaleDyanmicVariableDifferences(localeVariables) problems = identifyLocaleDyanmicVariableDifferences(localeVariables)
found_old_dynamic_variables = identifyAndPrintOldDynamicVariables( found_old_dynamic_variables = identifyAndPrintOldDynamicVariables(
localeVariablesOld, args.print_old_dynamic_variables localeVariablesOld, args.print_old_dynamic_variables
) )
@ -121,6 +122,25 @@ found_old_dynamic_variables = identifyAndPrintOldDynamicVariables(
if problems: if problems:
message = "There are issues with the locales." message = "There are issues with the locales."
if args.print_problem_strings:
string_to_locales = {}
for locale, locale_problems in problems.items():
if "additional_variables" in locale_problems:
for problem_string in locale_problems["additional_variables"].keys():
if problem_string not in string_to_locales:
string_to_locales[problem_string] = [locale]
else:
string_to_locales[problem_string].append(locale)
if "missing_variables" in locale_problems:
for problem_string in locale_problems["missing_variables"].keys():
if problem_string not in string_to_locales:
string_to_locales[problem_string] = [locale]
else:
string_to_locales[problem_string].append(locale)
console.info(f"Problem strings: {json.dumps(string_to_locales, indent=2)}")
message += " See above for problem strings and which locales they are in."
if args.print_problems: if args.print_problems:
prettyPrintIssuesTable(problems) prettyPrintIssuesTable(problems)
message += " See above for details." message += " See above for details."
@ -138,7 +158,7 @@ if problems:
if found_old_dynamic_variables: if found_old_dynamic_variables:
warning_message = ( warning_message = (
"Old dynamic variables were found in the locales. Please update the locales to use the new dynamic variables. " "Old dynamic variables were found in the locales. Please update the locales to use the new dynamic variables. "
) )
if args.print_old_dynamic_variables: if args.print_old_dynamic_variables:
if args.print_problems: if args.print_problems:
warning_message += "See above for details (before the problems table)." warning_message += "See above for details (before the problems table)."
@ -148,8 +168,6 @@ if found_old_dynamic_variables:
warning_message += "Run the script with --print-old-dynamic-variables to see the old dynamic variables." warning_message += "Run the script with --print-old-dynamic-variables to see the old dynamic variables."
console.warn(warning_message) console.warn(warning_message)
console.debug("Locales generation complete") console.debug("Locales generation complete")
timer.stop() timer.stop()

Loading…
Cancel
Save