Skip to content

Commit

Permalink
Merge pull request #2 from argosopentech/epub-fix
Browse files Browse the repository at this point in the history
Epub fix
  • Loading branch information
TheTakylo committed Aug 5, 2023
2 parents e668802 + 6735917 commit 5b28b6f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions argostranslatefiles/formats/epub.py
Expand Up @@ -24,15 +24,16 @@ def translate(self, underlying_translation: ITranslation, file_path: str):

for inzipinfo in inzip.infolist():
with inzip.open(inzipinfo) as infile:
if inzipinfo.filename == "OPS/content.opf" or inzipinfo.filename == "OPS/toc.ncx":
translatable_xml_filenames = ["OPS/content.opf", "OPS/toc.ncx", "OEBPS/content.opf", "OEBPS/toc.ncx"]
if inzipinfo.filename in translatable_xml_filenames:
soup = BeautifulSoup(infile.read(), 'xml')

itag = self.itag_of_soup(soup)
translated_tag = translate_tags(underlying_translation, itag)
translated_soup = self.soup_of_itag(translated_tag)

outzip.writestr(inzipinfo.filename, str(translated_soup))
elif re.search(r'OPS\/[a-zA-Z0-9\_]*.xhtml', inzipinfo.filename):
elif inzipinfo.filename.endswith('.html') or inzipinfo.filename.endswith('.xhtml'):
head = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>'
content = str(infile.read(), 'utf-8')
head_present = content.startswith(head)
Expand Down

0 comments on commit 5b28b6f

Please sign in to comment.