mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-30 01:37:17 +00:00
fix: [Language] fix language source
This commit is contained in:
parent
1c46bb4296
commit
f586baa0c5
5 changed files with 17 additions and 41 deletions
|
@ -388,6 +388,8 @@ class LanguageTranslator:
|
|||
return language
|
||||
|
||||
def translate(self, content, source=None, target="en"): # TODO source target
|
||||
if target not in LIST_LANGUAGES:
|
||||
return None
|
||||
translation = None
|
||||
if content:
|
||||
if not source:
|
||||
|
@ -407,15 +409,17 @@ class LanguageTranslator:
|
|||
return translation
|
||||
|
||||
|
||||
LIST_LANGUAGES = []
|
||||
LIST_LANGUAGES = {}
|
||||
def get_translation_languages():
|
||||
global LIST_LANGUAGES
|
||||
if not LIST_LANGUAGES:
|
||||
try:
|
||||
LIST_LANGUAGES = LanguageTranslator().languages()
|
||||
LIST_LANGUAGES = {}
|
||||
for lang in LanguageTranslator().languages():
|
||||
LIST_LANGUAGES[lang['iso']] = lang['language']
|
||||
except Exception as e:
|
||||
print(e)
|
||||
LIST_LANGUAGES = []
|
||||
LIST_LANGUAGES = {}
|
||||
return LIST_LANGUAGES
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ from lib.objects import ChatThreads
|
|||
from lib.objects import Messages
|
||||
from lib.objects import UsersAccount
|
||||
from lib.objects import Usernames
|
||||
from lib import Language
|
||||
|
||||
config_loader = ConfigLoader()
|
||||
r_db = config_loader.get_db_conn("Kvrocks_DB")
|
||||
|
@ -341,6 +342,8 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa
|
|||
if meta['subchannels']:
|
||||
meta['subchannels'] = get_subchannels_meta_from_global_id(meta['subchannels'])
|
||||
else:
|
||||
if translation_target not in Language.LIST_LANGUAGES:
|
||||
translation_target = None
|
||||
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
|
||||
return meta, 200
|
||||
|
||||
|
|
|
@ -629,43 +629,6 @@ def get_item_metadata(item_id, item_content=None):
|
|||
def get_item_content(item_id):
|
||||
return item_basic.get_item_content(item_id)
|
||||
|
||||
def get_item_content_html2text(item_id, item_content=None, ignore_links=False):
|
||||
if not item_content:
|
||||
item_content = get_item_content(item_id)
|
||||
h = html2text.HTML2Text()
|
||||
h.ignore_links = ignore_links
|
||||
h.ignore_images = ignore_links
|
||||
return h.handle(item_content)
|
||||
|
||||
def remove_all_urls_from_content(item_id, item_content=None):
|
||||
if not item_content:
|
||||
item_content = get_item_content(item_id)
|
||||
regex = r'\b(?:http://|https://)?(?:[a-zA-Z\d-]{,63}(?:\.[a-zA-Z\d-]{,63})+)(?:\:[0-9]+)*(?:/(?:$|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*\b'
|
||||
url_regex = re.compile(regex)
|
||||
urls = url_regex.findall(item_content)
|
||||
urls = sorted(urls, key=len, reverse=True)
|
||||
for url in urls:
|
||||
item_content = item_content.replace(url, '')
|
||||
|
||||
regex_pgp_public_blocs = r'-----BEGIN PGP PUBLIC KEY BLOCK-----[\s\S]+?-----END PGP PUBLIC KEY BLOCK-----'
|
||||
regex_pgp_signature = r'-----BEGIN PGP SIGNATURE-----[\s\S]+?-----END PGP SIGNATURE-----'
|
||||
regex_pgp_message = r'-----BEGIN PGP MESSAGE-----[\s\S]+?-----END PGP MESSAGE-----'
|
||||
re.compile(regex_pgp_public_blocs)
|
||||
re.compile(regex_pgp_signature)
|
||||
re.compile(regex_pgp_message)
|
||||
|
||||
res = re.findall(regex_pgp_public_blocs, item_content)
|
||||
for it in res:
|
||||
item_content = item_content.replace(it, '')
|
||||
res = re.findall(regex_pgp_signature, item_content)
|
||||
for it in res:
|
||||
item_content = item_content.replace(it, '')
|
||||
res = re.findall(regex_pgp_message, item_content)
|
||||
for it in res:
|
||||
item_content = item_content.replace(it, '')
|
||||
|
||||
return item_content
|
||||
|
||||
|
||||
# API
|
||||
# def get_item(request_dict):
|
||||
|
|
|
@ -82,6 +82,8 @@ def chats_explorer_chat():
|
|||
chat_id = request.args.get('id')
|
||||
instance_uuid = request.args.get('uuid')
|
||||
target = request.args.get('target')
|
||||
if target == "Don't Translate":
|
||||
target = None
|
||||
nb_messages = request.args.get('nb')
|
||||
page = request.args.get('page')
|
||||
chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target, nb=nb_messages, page=page)
|
||||
|
@ -111,6 +113,8 @@ def objects_subchannel_messages():
|
|||
subchannel_id = request.args.get('id')
|
||||
instance_uuid = request.args.get('uuid')
|
||||
target = request.args.get('target')
|
||||
if target == "Don't Translate":
|
||||
target = None
|
||||
nb_messages = request.args.get('nb')
|
||||
page = request.args.get('page')
|
||||
subchannel = chats_viewer.api_get_subchannel(subchannel_id, instance_uuid, translation_target=target, nb=nb_messages, page=page)
|
||||
|
@ -128,6 +132,8 @@ def objects_thread_messages():
|
|||
thread_id = request.args.get('id')
|
||||
instance_uuid = request.args.get('uuid')
|
||||
target = request.args.get('target')
|
||||
if target == "Don't Translate":
|
||||
target = None
|
||||
nb_messages = request.args.get('nb')
|
||||
page = request.args.get('page')
|
||||
thread = chats_viewer.api_get_thread(thread_id, instance_uuid, translation_target=target, nb=nb_messages, page=page)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<option selected value="{{ translation_target }}">{{ translation_target }}</option>
|
||||
{% endif %}
|
||||
{% for language in translation_languages %}
|
||||
<option value="{{ language['iso'] }}">{{ language['language'] }}</option>
|
||||
<option value="{{ language }}">{{ translation_languages[language] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue