mirror of
https://github.com/Azure/co-op-translator
synced 2026-08-09 12:00:08 +00:00
Core: Skip image migrations when images disabled (#366)
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "co_op_translator"
|
||||
version = "0.16.5"
|
||||
version = "0.16.6"
|
||||
description = "Easily automate the translation of your documentation into multiple languages to reach a global audience."
|
||||
authors = [
|
||||
"Minseok Song <minseok.song@mssong.com>",
|
||||
|
||||
@@ -646,60 +646,65 @@ class TranslationManager:
|
||||
all_errors = []
|
||||
|
||||
try:
|
||||
# Migrate legacy translated image filenames and update markdown/notebook links
|
||||
rename_map: dict[str, str] = {}
|
||||
migrated_image_count = 0
|
||||
if "images" in self.translation_types:
|
||||
# Migrate legacy translated image filenames and update markdown/notebook links
|
||||
rename_map: dict[str, str] = {}
|
||||
migrated_image_count = 0
|
||||
|
||||
try:
|
||||
rename_map = migrate_translated_image_filenames(
|
||||
self.image_dir, self.language_codes
|
||||
)
|
||||
migrated_image_count += len(rename_map)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image filename migration skipped: {e}")
|
||||
rename_map = {}
|
||||
|
||||
try:
|
||||
webp_rename_map = migrate_images_to_webp(
|
||||
self.image_dir, self.language_codes
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"WebP migration skipped: {e}")
|
||||
else:
|
||||
rename_map.update(webp_rename_map)
|
||||
migrated_image_count += len(webp_rename_map)
|
||||
|
||||
try:
|
||||
# Always run link migration to rewrite legacy flattened links in content,
|
||||
# even when no files were moved (empty rename_map)
|
||||
migrated_md = self.directory_manager.migrate_markdown_image_links(
|
||||
rename_map
|
||||
)
|
||||
migrated_nb = self.directory_manager.migrate_notebook_image_links(
|
||||
rename_map
|
||||
)
|
||||
logger.info(
|
||||
"Migrated %d image files and updated %d markdown and %d notebook files",
|
||||
migrated_image_count,
|
||||
migrated_md,
|
||||
migrated_nb,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image link migration skipped: {e}")
|
||||
|
||||
# As a safety net, canonicalize any remaining alias-based language dir segments in links
|
||||
try:
|
||||
md_fix, nb_fix = canonicalize_image_links_in_translations(
|
||||
self.translations_dir, self.image_dir
|
||||
)
|
||||
if md_fix or nb_fix:
|
||||
logger.info(
|
||||
"Canonicalized image links in %d markdown and %d notebooks",
|
||||
md_fix,
|
||||
nb_fix,
|
||||
try:
|
||||
rename_map = migrate_translated_image_filenames(
|
||||
self.image_dir, self.language_codes
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image link canonicalization skipped: {e}")
|
||||
migrated_image_count += len(rename_map)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image filename migration skipped: {e}")
|
||||
rename_map = {}
|
||||
|
||||
try:
|
||||
webp_rename_map = migrate_images_to_webp(
|
||||
self.image_dir, self.language_codes
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"WebP migration skipped: {e}")
|
||||
else:
|
||||
rename_map.update(webp_rename_map)
|
||||
migrated_image_count += len(webp_rename_map)
|
||||
|
||||
try:
|
||||
# Always run link migration to rewrite legacy flattened links in content,
|
||||
# even when no files were moved (empty rename_map)
|
||||
migrated_md = self.directory_manager.migrate_markdown_image_links(
|
||||
rename_map
|
||||
)
|
||||
migrated_nb = self.directory_manager.migrate_notebook_image_links(
|
||||
rename_map
|
||||
)
|
||||
logger.info(
|
||||
"Migrated %d image files and updated %d markdown and %d notebook files",
|
||||
migrated_image_count,
|
||||
migrated_md,
|
||||
migrated_nb,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image link migration skipped: {e}")
|
||||
|
||||
# As a safety net, canonicalize any remaining alias-based language dir segments in links
|
||||
try:
|
||||
md_fix, nb_fix = canonicalize_image_links_in_translations(
|
||||
self.translations_dir, self.image_dir
|
||||
)
|
||||
if md_fix or nb_fix:
|
||||
logger.info(
|
||||
"Canonicalized image links in %d markdown and %d notebooks",
|
||||
md_fix,
|
||||
nb_fix,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Image link canonicalization skipped: {e}")
|
||||
else:
|
||||
logger.info(
|
||||
"Skipping translated image migration because image translation is disabled"
|
||||
)
|
||||
|
||||
# Clean up files no longer needed in target directories
|
||||
logger.info("Removing orphaned files...")
|
||||
|
||||
Reference in New Issue
Block a user