Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Make translation update script more robust #7273

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions Utilities/Scripts/update_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def update_translations(component, source_code_dir, translations_dir, lupdate_pa
language=None, remove_obsolete_strings=False, source_file_regex=None, keep_temporary_files=False):

if language is None:
ts_filename_filter = f"{component}*.ts"
ts_filename_filter = f"{component}_*.ts"
else:
ts_filename_filter = f"{component}*_{language}.ts"
ts_filename_filter = f"{component}_{language}.ts"

ts_file_filter = f"{translations_dir}/{ts_filename_filter}"
ts_file_paths = glob.glob(ts_file_filter)
Expand Down Expand Up @@ -293,11 +293,20 @@ def to_translation_header(translation_context, text):
return result

import xml.etree.ElementTree as ET
tree = ET.parse(cli_xml_filename)
try:
tree = ET.parse(cli_xml_filename)
except ET.ParseError:
# Not a CLI module descriptor XML file
return False

root = tree.getroot()

translation_context = "CLI_" + os.path.splitext(os.path.basename(cli_xml_filename))[0]

if not root.find('executable') or not root.find('title'):
# Not a CLI module descriptor XML file
return False

cpp_header_str = f"// Generated automatically by update_translations.py from {os.path.basename(cli_xml_filename)}\n\n"

# Module information
Expand Down Expand Up @@ -396,6 +405,8 @@ def main(argv):
'DiffusionTensorTest.xml',
]
extract_translatable_from_cli_modules(cli_input_paths, cli_exclude_names)
else:
extract_translatable_from_cli_modules([args.source_code_dir])

update_translations(args.component, args.source_code_dir, args.translations_dir, args.lupdate_path,
args.language, args.remove_obsolete_strings, args.source_filter_regex, args.keep_temporary_files)
Expand Down