Jul-04-2021, 07:51 PM
I find the solution. The regex, was trying to translate all the inner contents of the tags, however you the content part of the meta tag isn't inner content. I had to make a separate check to see if it was a meta tag, And then did translation specifically for the meta tag under that check.
So, after those regex, you I should add this code:
So, after those regex, you I should add this code:
for pattern in patterns: for x in re.finditer(pattern, page): updated = True new = x.group(0) soup = BeautifulSoup(new, 'html.parser') if pattern != pattern4: recursively_translate(soup) else: meta = soup.find('meta') meta['content'] = translator.translate(meta['content'], dest=destination_language).text soup = soup.encode(formatter=UnsortedAttributes()).decode('utf-8') page = page.replace(new, soup)