Synchronize chapter and navigation translations with Chinese prose indentation

This commit is contained in:
Kai Tan
2026-10-08 07:59:01 +08:00
parent caf9d8f4bb
commit a158b4e26c
18 changed files with 613 additions and 11 deletions
+7 -2
View File
@@ -37,15 +37,20 @@ def write_preserving_package(original, structure, output):
etree.SubElement(manifest, f'{{{OPF}}}item', id=css_id, href=css_href, **{'media-type': 'text/css'})
replacements[css_archive_path] = (Path(__file__).parent/'bilingual_style.css').read_bytes()
for item_id, resource in structure.resources.items():
if resource.media_type != 'application/xhtml+xml' or not resource.content:
if resource.media_type not in {'application/xhtml+xml','application/x-dtbncx+xml'} or not resource.content:
continue
if 'nav' in (items.get(item_id).get('properties', '') if item_id in items else '').split() and 'translation-for' not in resource.content and 'class="translation"' not in resource.content:
if 'nav' in (items.get(item_id).get('properties', '') if item_id in items else '').split() and not resource.translation_modified and 'translation-for' not in resource.content and 'class="translation"' not in resource.content:
continue
if item_id not in items:
raise ValueError(f'Unknown package item: {item_id}')
archive_path = posixpath.normpath(posixpath.join(base, unquote(items[item_id].get('href'))))
if archive_path not in source.namelist():
raise ValueError(f'Missing source resource: {archive_path}')
if resource.media_type=='application/x-dtbncx+xml':
if resource.translation_modified:
etree.fromstring(resource.content.encode(),etree.XMLParser(resolve_entities=False,no_network=True))
replacements[archive_path]=resource.content.encode()
continue
soup = parse_html(resource.content)
soup.html['xmlns'] = 'http://www.w3.org/1999/xhtml'
soup.html['xmlns:epub'] = 'http://www.idpf.org/2007/ops'