Message text direction for certain languages

merge-requests/30/head
Bob Mottram 2022-12-16 21:43:34 +00:00
parent 3dbfb7eb82
commit d741e68dc0
4 changed files with 59 additions and 1 deletions

View File

@ -653,6 +653,17 @@ a:focus {
hyphens: auto;
text-wrap: pretty;
text-align: justify;
direction: ltr;
}
.message_rtl {
margin-left: 0%;
margin-right: 0%;
width: 100%;
hyphens: auto;
text-wrap: pretty;
text-align: justify;
direction: rtl;
}
.addedHashtag:link {

View File

@ -219,6 +219,33 @@ def get_content_from_post(post_json_object: {}, system_language: str,
return standardize_text(content)
def get_language_from_post(post_json_object: {}, system_language: str,
languages_understood: [],
content_type: str = "content") -> str:
"""Returns the content language from the post
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_type):
return system_language
map_dict = content_type + 'Map'
if this_post_json.get(map_dict):
if isinstance(this_post_json[map_dict], dict):
if this_post_json[map_dict].get(system_language):
sys_lang = this_post_json[map_dict][system_language]
if isinstance(sys_lang, str):
return system_language
else:
# is there a contentMap/summaryMap entry for one of
# the understood languages?
for lang in languages_understood:
if this_post_json[map_dict].get(lang):
return lang
return system_language
def get_media_descriptions_from_post(post_json_object: {}) -> str:
"""Returns all attached media descriptions as a single text.
This is used for filtering

View File

@ -35,6 +35,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_language_from_post
from utils import get_summary_from_post
from utils import has_object_dict
from utils import update_announce_collection
@ -78,6 +79,7 @@ from content import get_mentions_from_html
from content import switch_words
from person import is_person_snoozed
from person import get_person_avatar_url
from webapp_utils import language_right_to_left
from webapp_utils import get_banner_file
from webapp_utils import get_avatar_image_url
from webapp_utils import update_avatar_image_cache
@ -2163,6 +2165,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
languages_understood = get_actor_languages_list(actor_json)
content_str = get_content_from_post(post_json_object, system_language,
languages_understood)
content_language = \
get_language_from_post(post_json_object, system_language,
languages_understood)
content_str = dont_speak_hashtags(content_str)
attachment_str, gallery_str = \
@ -2248,6 +2253,9 @@ def individual_post_as_html(signing_priv_key_pem: str,
if not content_str:
content_str = get_content_from_post(post_json_object, system_language,
languages_understood)
content_language = \
get_language_from_post(post_json_object, system_language,
languages_understood)
content_str = dont_speak_hashtags(content_str)
if not content_str:
content_str = \
@ -2429,7 +2437,10 @@ def individual_post_as_html(signing_priv_key_pem: str,
content_str = ''
else:
if not is_patch:
content_str = ' <div class="message">' + \
message_class = 'message'
if language_right_to_left(content_language):
message_class = 'message_rtl'
content_str = ' <div class="' + message_class + '">' + \
content_str + \
' </div>\n'
else:

View File

@ -1944,3 +1944,12 @@ def text_mode_browser(ua_str: str) -> bool:
if agent in ua_str:
return True
return False
def language_right_to_left(language: str) -> bool:
"""is the given language written from right to left?
"""
rtl_languages = ('ar', 'fa')
if language in rtl_languages:
return True
return False