Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,18 +40,19 @@ def split_text(text, limit=4000):
|
|
| 40 |
def translate_html_content(text, source_lang, target_lang):
|
| 41 |
soup = BeautifulSoup(text, 'html.parser')
|
| 42 |
|
| 43 |
-
for node in soup.find_all(
|
| 44 |
if isinstance(node, NavigableString) and node.strip():
|
| 45 |
original_text = node.strip()
|
| 46 |
chunks = split_text(original_text)
|
| 47 |
translated_chunks = [translate(chunk, target_lang, source_lang) for chunk in chunks]
|
| 48 |
translated_text = ''.join(translated_chunks)
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
if node.previous_sibling and
|
| 52 |
translated_text = ' ' + translated_text
|
| 53 |
-
if node.next_sibling and
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
node.replace_with(translated_text)
|
| 57 |
|
|
|
|
| 40 |
def translate_html_content(text, source_lang, target_lang):
|
| 41 |
soup = BeautifulSoup(text, 'html.parser')
|
| 42 |
|
| 43 |
+
for node in soup.find_all(string=True): # Cambiado de text=True a string=True
|
| 44 |
if isinstance(node, NavigableString) and node.strip():
|
| 45 |
original_text = node.strip()
|
| 46 |
chunks = split_text(original_text)
|
| 47 |
translated_chunks = [translate(chunk, target_lang, source_lang) for chunk in chunks]
|
| 48 |
translated_text = ''.join(translated_chunks)
|
| 49 |
|
| 50 |
+
# Verificar espacios antes y despu茅s del nodo
|
| 51 |
+
if node.previous_sibling and isinstance(node.previous_sibling, NavigableString):
|
| 52 |
translated_text = ' ' + translated_text
|
| 53 |
+
if node.next_sibling and isinstance(node.next_sibling, NavigableString): # Verificaci贸n corregida
|
| 54 |
+
if not node.next_sibling.startswith(' '):
|
| 55 |
+
translated_text += ' '
|
| 56 |
|
| 57 |
node.replace_with(translated_text)
|
| 58 |
|