chg: [message] UI translate message object

dev
terrtia 2024-01-16 14:38:29 +01:00
parent f586baa0c5
commit edf0c4c454
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
4 changed files with 11 additions and 4 deletions

View File

@ -388,7 +388,7 @@ class LanguageTranslator:
return language return language
def translate(self, content, source=None, target="en"): # TODO source target def translate(self, content, source=None, target="en"): # TODO source target
if target not in LIST_LANGUAGES: if target not in get_translation_languages():
return None return None
translation = None translation = None
if content: if content:

View File

@ -394,11 +394,11 @@ def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=
meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page) meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page)
return meta, 200 return meta, 200
def api_get_message(message_id): def api_get_message(message_id, translation_target=None):
message = Messages.Message(message_id) message = Messages.Message(message_id)
if not message.exists(): if not message.exists():
return {"status": "error", "reason": "Unknown uuid"}, 404 return {"status": "error", "reason": "Unknown uuid"}, 404
meta = message.get_meta({'chat', 'content', 'icon', 'images', 'link', 'parent', 'parent_meta', 'user-account'}) meta = message.get_meta({'chat', 'content', 'files-names', 'icon', 'images', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target)
# if meta['chat']: # if meta['chat']:
# print(meta['chat']) # print(meta['chat'])
# # meta['chat'] = # # meta['chat'] =

View File

@ -163,13 +163,17 @@ def chats_explorer_chat_participants():
@login_read_only @login_read_only
def objects_message(): def objects_message():
message_id = request.args.get('id') message_id = request.args.get('id')
message = chats_viewer.api_get_message(message_id) target = request.args.get('target')
if target == "Don't Translate":
target = None
message = chats_viewer.api_get_message(message_id, translation_target=target)
if message[1] != 200: if message[1] != 200:
return create_json_response(message[0], message[1]) return create_json_response(message[0], message[1])
else: else:
message = message[0] message = message[0]
languages = Language.get_translation_languages() languages = Language.get_translation_languages()
return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label, return render_template('ChatMessage.html', meta=message, bootstrap_label=bootstrap_label,
translation_languages=languages, translation_target=target,
modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message')) modal_add_tags=Tag.get_modal_add_tags(message['id'], object_type='message'))
@chats_explorer.route("/objects/user-account", methods=['GET']) @chats_explorer.route("/objects/user-account", methods=['GET'])

View File

@ -135,6 +135,9 @@
{% include 'objects/image/block_blur_img_slider.html' %} {% include 'objects/image/block_blur_img_slider.html' %}
{% with translate_url=url_for('chats_explorer.objects_message', id=meta['id']), obj_id=meta['id'] %}
{% include 'chats_explorer/block_translation.html' %}
{% endwith %}
<div class="position-relative"> <div class="position-relative">