tx3bas commited on
Commit
b695d62
verified
1 Parent(s): 9884f77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
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(text=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
- # Asegurar espacios alrededor del texto
51
- if node.previous_sibling and not node.previous_sibling.endswith(' '):
52
  translated_text = ' ' + translated_text
53
- if node.next_sibling and not node.next_sibling.startswith(' '):
54
- translated_text += ' '
 
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