mirror of https://gitlab.com/bashrc2/epicyon
Return the language for a reply post
So that replies are by default in the same languagemain
parent
ae0e6e4919
commit
9a08780080
15
daemon.py
15
daemon.py
|
@ -264,6 +264,7 @@ from shares import shares_catalog_account_endpoint
|
|||
from shares import shares_catalog_csv_endpoint
|
||||
from categories import set_hashtag_category
|
||||
from categories import update_hashtag_categories
|
||||
from languages import get_reply_language
|
||||
from languages import load_default_post_languages
|
||||
from languages import set_default_post_language
|
||||
from languages import get_actor_languages
|
||||
|
@ -15772,12 +15773,22 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
custom_submit_text = get_config_param(base_dir, 'customSubmitText')
|
||||
|
||||
default_post_language = self.server.system_language
|
||||
if self.server.default_post_language.get(nickname):
|
||||
default_post_language = \
|
||||
self.server.default_post_language[nickname]
|
||||
|
||||
post_json_object = None
|
||||
if in_reply_to_url:
|
||||
reply_post_filename = \
|
||||
locate_post(base_dir, nickname, domain, in_reply_to_url)
|
||||
if reply_post_filename:
|
||||
post_json_object = load_json(reply_post_filename)
|
||||
if post_json_object:
|
||||
reply_language = \
|
||||
get_reply_language(base_dir, post_json_object)
|
||||
if reply_language:
|
||||
default_post_language = reply_language
|
||||
|
||||
bold_reading = False
|
||||
if self.server.bold_reading.get(nickname):
|
||||
|
@ -15790,10 +15801,6 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.domain_full,
|
||||
self.server.person_cache)
|
||||
|
||||
default_post_language = self.server.system_language
|
||||
if self.server.default_post_language.get(nickname):
|
||||
default_post_language = \
|
||||
self.server.default_post_language[nickname]
|
||||
msg = \
|
||||
html_new_post(edit_post_params, media_instance,
|
||||
translate,
|
||||
|
|
17
languages.py
17
languages.py
|
@ -369,3 +369,20 @@ def load_default_post_languages(base_dir: str) -> {}:
|
|||
print('EX: Unable to read default post language ' +
|
||||
default_post_language_filename)
|
||||
return result
|
||||
|
||||
|
||||
def get_reply_language(base_dir: str,
|
||||
post_json_object: {}) -> str:
|
||||
"""Returns the language that te given post was written in
|
||||
"""
|
||||
post_obj = post_json_object
|
||||
if has_object_dict(post_json_object):
|
||||
post_obj = post_json_object['object']
|
||||
if not post_obj.get('contentMap'):
|
||||
return None
|
||||
for lang, content in post_obj['contentMap'].items():
|
||||
lang_filename = base_dir + '/translations/' + lang + '.json'
|
||||
if not os.path.isfile(lang_filename):
|
||||
continue
|
||||
return lang
|
||||
return None
|
||||
|
|
31
tests.py
31
tests.py
|
@ -176,6 +176,7 @@ from mastoapiv1 import get_nickname_from_masto_api_v1id
|
|||
from webapp_post import prepare_html_post_nickname
|
||||
from speaker import speaker_replace_links
|
||||
from markdown import markdown_to_html
|
||||
from languages import get_reply_language
|
||||
from languages import set_actor_languages
|
||||
from languages import get_actor_languages
|
||||
from languages import get_links_from_content
|
||||
|
@ -7608,6 +7609,35 @@ def _test_emoji_in_actor_name(base_dir: str) -> None:
|
|||
assert actor_json['tag'][0]['name'] == ':verified:'
|
||||
|
||||
|
||||
def _test_reply_language(base_dir: str) -> None:
|
||||
print('reply_language')
|
||||
|
||||
post_json_object = {
|
||||
'object': {
|
||||
'contentMap': {
|
||||
'en': 'This is some content'
|
||||
}
|
||||
}
|
||||
}
|
||||
assert get_reply_language(base_dir, post_json_object) == 'en'
|
||||
|
||||
post_json_object = {
|
||||
'object': {
|
||||
'contentMap': {
|
||||
'xx': 'This is some content',
|
||||
'de': 'This is some content'
|
||||
}
|
||||
}
|
||||
}
|
||||
assert get_reply_language(base_dir, post_json_object) == 'de'
|
||||
|
||||
post_json_object = {
|
||||
'object': {
|
||||
}
|
||||
}
|
||||
assert not get_reply_language(base_dir, post_json_object)
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
base_dir = os.getcwd()
|
||||
print('Running tests...')
|
||||
|
@ -7625,6 +7655,7 @@ def run_all_tests():
|
|||
_test_checkbox_names()
|
||||
_test_thread_functions()
|
||||
_test_functions()
|
||||
_test_reply_language(base_dir)
|
||||
_test_emoji_in_actor_name(base_dir)
|
||||
_test_uninvert()
|
||||
_test_hashtag_maps()
|
||||
|
|
Loading…
Reference in New Issue