Update app.py
Browse files
app.py
CHANGED
@@ -34,18 +34,19 @@ def translate_html_content(text, source_lang, target_lang):
|
|
34 |
soup = BeautifulSoup(text, 'html.parser')
|
35 |
|
36 |
# Traducir nodos de texto
|
37 |
-
for node in soup.find_all(
|
38 |
if isinstance(node, NavigableString) and node.strip():
|
39 |
original_text = node.strip()
|
40 |
chunks = split_text(original_text)
|
41 |
translated_chunks = [translate(chunk, target_lang, source_lang) for chunk in chunks]
|
42 |
translated_text = ''.join(translated_chunks)
|
43 |
|
44 |
-
#
|
45 |
-
if node.previous_sibling and
|
46 |
translated_text = ' ' + translated_text
|
47 |
-
if node.next_sibling and
|
48 |
-
|
|
|
49 |
|
50 |
node.replace_with(translated_text)
|
51 |
|
|
|
34 |
soup = BeautifulSoup(text, 'html.parser')
|
35 |
|
36 |
# Traducir nodos de texto
|
37 |
+
for node in soup.find_all(string=True): # Cambiado de text=True a string=True
|
38 |
if isinstance(node, NavigableString) and node.strip():
|
39 |
original_text = node.strip()
|
40 |
chunks = split_text(original_text)
|
41 |
translated_chunks = [translate(chunk, target_lang, source_lang) for chunk in chunks]
|
42 |
translated_text = ''.join(translated_chunks)
|
43 |
|
44 |
+
# Verificar espacios antes y después del nodo
|
45 |
+
if node.previous_sibling and isinstance(node.previous_sibling, NavigableString):
|
46 |
translated_text = ' ' + translated_text
|
47 |
+
if node.next_sibling and isinstance(node.next_sibling, NavigableString):
|
48 |
+
if not node.next_sibling.startswith(' '): # Verificación adicional
|
49 |
+
translated_text += ' '
|
50 |
|
51 |
node.replace_with(translated_text)
|
52 |
|