You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The contents of the comments get translated correctly, but when reconstructing the BeautifulSoup object their tags are lost, causing the final translated document to show the contents of the comments when opened with a web browser.
The issue, as far as I can work out, is that neither itag_of_soup nor soup_of_itag differentiate between a bs4.element.NavigableString and a bs4.element.Comment (which inherits from the former).
So, itag_of_soup returns an str object regardless of whether its processing a NavigableString or a Comment. When soup_of_itag is called, it checks if the object passed to it is an instance of str and if so constructs a NavigableString, which for the case of comments results in losing the <!--- ---> characters in the final document.
Here's an example:
importargostranslate.translateimporttranslatehtml# Original "file"content="""<html> <head> <title>Test</title> </head> <body> <!-- This should not be seen in a browser --> <h1>Welcome to Test!</h1> </body></html>"""# Define languages for translation from English to Hindien=argostranslate.translate.get_language_from_code("en")
hi=argostranslate.translate.get_language_from_code("hi")
ut=en.get_translation(hi)
# Translate the file with translate_htmlcontent=translatehtml.translate_html(ut, content)
# Write the translated filewithopen("test.html", "wt") asfp:
fp.write(str(content))
Original file
Translation
The text was updated successfully, but these errors were encountered:
The contents of the comments get translated correctly, but when reconstructing the
BeautifulSoup
object their tags are lost, causing the final translated document to show the contents of the comments when opened with a web browser.The issue, as far as I can work out, is that neither
itag_of_soup
norsoup_of_itag
differentiate between abs4.element.NavigableString
and abs4.element.Comment
(which inherits from the former).So,
itag_of_soup
returns anstr
object regardless of whether its processing aNavigableString
or aComment
. Whensoup_of_itag
is called, it checks if the object passed to it is an instance ofstr
and if so constructs aNavigableString
, which for the case of comments results in losing the<!--- --->
characters in the final document.Here's an example:
The text was updated successfully, but these errors were encountered: