mirror of https://gitlab.com/bashrc2/epicyon
Handle post summary translations
parent
2363ced253
commit
0d32c0a32a
35
utils.py
35
utils.py
|
@ -89,34 +89,45 @@ def get_actor_languages_list(actor_json: {}) -> []:
|
|||
|
||||
|
||||
def get_content_from_post(post_json_object: {}, system_language: str,
|
||||
languages_understood: []) -> str:
|
||||
languages_understood: [],
|
||||
contentType: str = "content") -> str:
|
||||
"""Returns the content from the post in the given language
|
||||
including searching for a matching entry within contentMap
|
||||
"""
|
||||
this_post_json = post_json_object
|
||||
if has_object_dict(post_json_object):
|
||||
this_post_json = post_json_object['object']
|
||||
if not this_post_json.get('content'):
|
||||
if not this_post_json.get(contentType):
|
||||
return ''
|
||||
content = ''
|
||||
if this_post_json.get('contentMap'):
|
||||
if isinstance(this_post_json['contentMap'], dict):
|
||||
if this_post_json['contentMap'].get(system_language):
|
||||
sys_lang = this_post_json['contentMap'][system_language]
|
||||
mapDict = contentType + 'Map'
|
||||
if this_post_json.get(mapDict):
|
||||
if isinstance(this_post_json[mapDict], dict):
|
||||
if this_post_json[mapDict].get(system_language):
|
||||
sys_lang = this_post_json[mapDict][system_language]
|
||||
if isinstance(sys_lang, str):
|
||||
return this_post_json['contentMap'][system_language]
|
||||
return this_post_json[mapDict][system_language]
|
||||
else:
|
||||
# is there a contentMap entry for one of
|
||||
# is there a contentMap/summaryMap entry for one of
|
||||
# the understood languages?
|
||||
for lang in languages_understood:
|
||||
if this_post_json['contentMap'].get(lang):
|
||||
return this_post_json['contentMap'][lang]
|
||||
if this_post_json[mapDict].get(lang):
|
||||
return this_post_json[mapDict][lang]
|
||||
else:
|
||||
if isinstance(this_post_json['content'], str):
|
||||
content = this_post_json['content']
|
||||
if isinstance(this_post_json[contentType], str):
|
||||
content = this_post_json[contentType]
|
||||
return content
|
||||
|
||||
|
||||
def get_summary_from_post(post_json_object: {}, system_language: str,
|
||||
languages_understood: []) -> str:
|
||||
"""Returns the summary from the post in the given language
|
||||
including searching for a matching entry within summaryMap
|
||||
"""
|
||||
return get_content_from_post(post_json_object, system_language,
|
||||
languages_understood, "summary")
|
||||
|
||||
|
||||
def get_base_content_from_post(post_json_object: {},
|
||||
system_language: str) -> str:
|
||||
"""Returns the content from the post in the given language
|
||||
|
|
|
@ -28,6 +28,7 @@ from utils import remove_html
|
|||
from utils import get_actor_languages_list
|
||||
from utils import get_base_content_from_post
|
||||
from utils import get_content_from_post
|
||||
from utils import get_summary_from_post
|
||||
from utils import has_object_dict
|
||||
from utils import update_announce_collection
|
||||
from utils import is_pgp_encrypted
|
||||
|
@ -1852,6 +1853,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
if translate.get(sensitive_str):
|
||||
sensitive_str = translate[sensitive_str]
|
||||
post_json_object['object']['summary'] = sensitive_str
|
||||
post_json_object['object']['summaryMap'] = {
|
||||
system_language: sensitive_str
|
||||
}
|
||||
|
||||
# add an extra line if there is a content warning,
|
||||
# for better vertical spacing on mobile
|
||||
|
@ -1860,6 +1864,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
|
||||
if not post_json_object['object'].get('summary'):
|
||||
post_json_object['object']['summary'] = ''
|
||||
post_json_object['object']['summaryMap'] = {
|
||||
system_language: ''
|
||||
}
|
||||
|
||||
if post_json_object['object'].get('cipherText'):
|
||||
post_json_object['object']['content'] = \
|
||||
|
@ -1883,10 +1890,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
if not content_str:
|
||||
return ''
|
||||
|
||||
summary_str = get_summary_from_post(post_json_object, system_language,
|
||||
languages_understood)
|
||||
is_patch = is_git_patch(base_dir, nickname, domain,
|
||||
post_json_object['object']['type'],
|
||||
post_json_object['object']['summary'],
|
||||
content_str)
|
||||
summary_str, content_str)
|
||||
|
||||
_log_post_timing(enable_timing_log, post_start_time, '16')
|
||||
|
||||
|
@ -1921,12 +1929,11 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
else:
|
||||
post_id = 'post' + str(create_password(8))
|
||||
content_str = ''
|
||||
if post_json_object['object'].get('summary'):
|
||||
cw_str = str(post_json_object['object']['summary'])
|
||||
if summary_str:
|
||||
cw_str = \
|
||||
add_emoji_to_display_name(session, base_dir, http_prefix,
|
||||
nickname, domain,
|
||||
cw_str, False)
|
||||
summary_str, False)
|
||||
content_str += \
|
||||
'<label class="cw">' + cw_str + '</label>\n '
|
||||
if is_moderation_post:
|
||||
|
|
Loading…
Reference in New Issue