Core: Avoid bootstrapping text metadata for manual translations (#369)

This commit is contained in:
Minseok Song
2026-02-17 02:09:37 +09:00
committed by GitHub
parent 2c57355850
commit 8f2266669f
2 changed files with 30 additions and 7 deletions
@@ -1407,13 +1407,10 @@ class TranslationManager:
else None
)
if not legacy_hash:
save_text_metadata_for_source(
lang_dir,
original_file,
lang_code,
root_dir=self.root_dir,
)
migrated += 1
# If there is no legacy inline metadata, do not synthesize
# a fresh metadata record from the current source hash.
# Doing so would incorrectly mark unknown/manual translations
# as up-to-date and skip retranslation.
continue
extra_fields = {"original_hash": legacy_hash}
@@ -245,6 +245,32 @@ def test_is_translation_outdated_walks_up_to_lang_dir(tmp_path):
assert "lesson-1/README.md" in data
def test_migrate_legacy_inline_text_metadata_skips_files_without_legacy_block(tmp_path):
root_dir = tmp_path
translations_dir = root_dir / "translations"
lang_dir = translations_dir / "ko"
source_file = root_dir / "guide.md"
source_file.write_text("# Source\n", encoding="utf-8")
translated_file = lang_dir / "guide.md"
translated_file.parent.mkdir(parents=True, exist_ok=True)
translated_file.write_text("# Manual translated content\n", encoding="utf-8")
manager = MagicMock()
manager.root_dir = root_dir
manager.translations_dir = translations_dir
manager.language_codes = ["ko"]
manager._migrate_legacy_inline_text_metadata = (
TranslationManager._migrate_legacy_inline_text_metadata.__get__(manager)
)
migrated = manager._migrate_legacy_inline_text_metadata()
assert migrated == 0
assert not (lang_dir / ".co-op-translator.json").exists()
@pytest.mark.asyncio
async def test_retranslate_outdated_files(mock_translation_manager, temp_project_dir):
"""Tests retranslation of outdated files."""