Skip to content

Commit

Permalink
ENH: Make translation update script more robust
Browse files Browse the repository at this point in the history
SlicerIGT translation files were found by Slicer component. Translations were only extracted from CLI module XMLs for Slicer but not for other components.
  • Loading branch information
lassoan authored and pieper committed Oct 10, 2023
1 parent 57b8434 commit 93ee298
Showing 1 changed file with 14 additions and 3 deletions.
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

0 comments on commit 93ee298

Please sign in to comment.