yihong0618 / bilingual_book_maker

Make bilingual epub books Using AI translate
MIT License
7.31k stars 1.05k forks source link

REQ: Output translated strings to seperate file #169

Open ArieKindicator opened 1 year ago

ArieKindicator commented 1 year ago

At the moment the output is an bilingual (epub) file, that contains text

… -orginal language sentence/paragraph/text -translated language sentence/paragraph/text -orginal language sentence/paragraph/text -translated language sentence/paragraph/text …

I would like to output/export all translated strings to a separate (epub) file , or output to two files 1) bilingual file (default output), 2) translated strings file.

adrbn commented 1 year ago

This feature has been addressed by a participant here : https://github.com/yihong0618/bilingual_book_maker/issues/170#issuecomment-1472130594

Just add p.extract() to line 125 of the _epubloader.py file in the loader directory to produce only the translation.

It should look like that :

                                new_p.string = self.translate_model.translate(p.text)
                                self.p_to_save.append(new_p.text)
                        p.insert_after(new_p)
                      p.extract()
                        index += 1
                        if index % 20 == 0:
                            self._save_progress()```

EDIT : This fix worked at the time it was posted, which is when the _epubloader.py was still at an earlier version. Not sure how it could be implemented in the newer commits tho as the whole file got rewritten.

EDIT #2 : I managed to download the last commit for which the so-called fix worked, applied the tweak and put up the repo under my profile. You can find it here and it should work correctly to answer your original request : https://github.com/adrbn/translated_book_maker