mirror of
				https://github.com/searxng/searxng
				synced 2024-01-01 19:24:07 +01:00 
			
		
		
		
	[feat] mozhi: fix crash, support synonyms and definition
This commit is contained in:
		
							parent
							
								
									1fe13d0ba4
								
							
						
					
					
						commit
						df15c21b35
					
				
					 1 changed files with 9 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
import random
 | 
			
		||||
import re
 | 
			
		||||
from urllib.parse import urlencode
 | 
			
		||||
from flask_babel import gettext
 | 
			
		||||
 | 
			
		||||
about = {
 | 
			
		||||
    "website": 'https://codeberg.org/aryak/mozhi',
 | 
			
		||||
| 
						 | 
				
			
			@ -43,13 +44,18 @@ def response(resp):
 | 
			
		|||
 | 
			
		||||
    if translation['word_choices']:
 | 
			
		||||
        for word in translation['word_choices']:
 | 
			
		||||
            infobox += f"<dl><dt>{word['word']}</dt>"
 | 
			
		||||
            infobox += f"<dl><dt>{word['word']}: {word['definition']}</dt>"
 | 
			
		||||
 | 
			
		||||
            for example in word['examples_target']:
 | 
			
		||||
                infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
 | 
			
		||||
            if word['examples_target']:
 | 
			
		||||
                for example in word['examples_target']:
 | 
			
		||||
                    infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
 | 
			
		||||
                    infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
 | 
			
		||||
 | 
			
		||||
            infobox += "</dl>"
 | 
			
		||||
 | 
			
		||||
    if translation['source_synonyms']:
 | 
			
		||||
        infobox += f"<dl><dt>{gettext('Synonyms')}: {', '.join(translation['source_synonyms'])}</dt></dl>"
 | 
			
		||||
 | 
			
		||||
    result = {
 | 
			
		||||
        'infobox': translation['translated-text'],
 | 
			
		||||
        'content': infobox,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue