mirror of https://gitlab.com/bashrc2/epicyon
Set default posting language
parent
4a906f143f
commit
ae0e6e4919
29
daemon.py
29
daemon.py
|
@ -264,6 +264,8 @@ from shares import shares_catalog_account_endpoint
|
||||||
from shares import shares_catalog_csv_endpoint
|
from shares import shares_catalog_csv_endpoint
|
||||||
from categories import set_hashtag_category
|
from categories import set_hashtag_category
|
||||||
from categories import update_hashtag_categories
|
from categories import update_hashtag_categories
|
||||||
|
from languages import load_default_post_languages
|
||||||
|
from languages import set_default_post_language
|
||||||
from languages import get_actor_languages
|
from languages import get_actor_languages
|
||||||
from languages import set_actor_languages
|
from languages import set_actor_languages
|
||||||
from languages import get_understood_languages
|
from languages import get_understood_languages
|
||||||
|
@ -3492,6 +3494,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.domain_full,
|
self.server.domain_full,
|
||||||
self.server.person_cache)
|
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 = \
|
msg = \
|
||||||
html_new_post({}, False, self.server.translate,
|
html_new_post({}, False, self.server.translate,
|
||||||
base_dir,
|
base_dir,
|
||||||
|
@ -3532,7 +3538,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
bold_reading,
|
bold_reading,
|
||||||
self.server.dogwhistles,
|
self.server.dogwhistles,
|
||||||
self.server.min_images_for_accounts,
|
self.server.min_images_for_accounts,
|
||||||
None, None)
|
None, None, default_post_language)
|
||||||
if msg:
|
if msg:
|
||||||
msg = msg.encode('utf-8')
|
msg = msg.encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
@ -3648,6 +3654,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.domain_full,
|
self.server.domain_full,
|
||||||
self.server.person_cache)
|
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 = \
|
msg = \
|
||||||
html_new_post({}, False, self.server.translate,
|
html_new_post({}, False, self.server.translate,
|
||||||
base_dir,
|
base_dir,
|
||||||
|
@ -3687,7 +3697,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
bold_reading,
|
bold_reading,
|
||||||
self.server.dogwhistles,
|
self.server.dogwhistles,
|
||||||
self.server.min_images_for_accounts,
|
self.server.min_images_for_accounts,
|
||||||
None, None)
|
None, None, default_post_language)
|
||||||
if msg:
|
if msg:
|
||||||
msg = msg.encode('utf-8')
|
msg = msg.encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
@ -15780,6 +15790,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.domain_full,
|
self.server.domain_full,
|
||||||
self.server.person_cache)
|
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 = \
|
msg = \
|
||||||
html_new_post(edit_post_params, media_instance,
|
html_new_post(edit_post_params, media_instance,
|
||||||
translate,
|
translate,
|
||||||
|
@ -15822,7 +15836,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
bold_reading,
|
bold_reading,
|
||||||
self.server.dogwhistles,
|
self.server.dogwhistles,
|
||||||
self.server.min_images_for_accounts,
|
self.server.min_images_for_accounts,
|
||||||
new_post_month, new_post_year)
|
new_post_month, new_post_year,
|
||||||
|
default_post_language)
|
||||||
if not msg:
|
if not msg:
|
||||||
print('Error replying to ' + in_reply_to_url)
|
print('Error replying to ' + in_reply_to_url)
|
||||||
self._404()
|
self._404()
|
||||||
|
@ -20065,6 +20080,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields['location'] = None
|
fields['location'] = None
|
||||||
if not fields.get('languagesDropdown'):
|
if not fields.get('languagesDropdown'):
|
||||||
fields['languagesDropdown'] = self.server.system_language
|
fields['languagesDropdown'] = self.server.system_language
|
||||||
|
set_default_post_language(self.server.base_dir, nickname,
|
||||||
|
self.server.domain,
|
||||||
|
fields['languagesDropdown'])
|
||||||
|
self.server.default_post_language[nickname] = \
|
||||||
|
fields['languagesDropdown']
|
||||||
|
|
||||||
if not citations_button_press:
|
if not citations_button_press:
|
||||||
# Store a file which contains the time in seconds
|
# Store a file which contains the time in seconds
|
||||||
|
@ -22344,6 +22364,9 @@ def run_daemon(max_hashtags: int,
|
||||||
# which accounts should minimize all attached images by default
|
# which accounts should minimize all attached images by default
|
||||||
httpd.min_images_for_accounts = load_min_images_for_accounts(base_dir)
|
httpd.min_images_for_accounts = load_min_images_for_accounts(base_dir)
|
||||||
|
|
||||||
|
# default language for each account when creating a new post
|
||||||
|
httpd.default_post_language = load_default_post_languages(base_dir)
|
||||||
|
|
||||||
# caches css files
|
# caches css files
|
||||||
httpd.css_cache = {}
|
httpd.css_cache = {}
|
||||||
|
|
||||||
|
|
43
languages.py
43
languages.py
|
@ -8,7 +8,10 @@ __status__ = "Production"
|
||||||
__module_group__ = "Core"
|
__module_group__ = "Core"
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from urllib import request, parse
|
from urllib import request, parse
|
||||||
|
from utils import is_account_dir
|
||||||
|
from utils import acct_dir
|
||||||
from utils import get_actor_languages_list
|
from utils import get_actor_languages_list
|
||||||
from utils import remove_html
|
from utils import remove_html
|
||||||
from utils import has_object_dict
|
from utils import has_object_dict
|
||||||
|
@ -326,3 +329,43 @@ def auto_translate_post(base_dir: str, post_json_object: {},
|
||||||
translated_text
|
translated_text
|
||||||
return translated_text
|
return translated_text
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def set_default_post_language(base_dir: str, nickname: str, domain: str,
|
||||||
|
language: str) -> None:
|
||||||
|
"""Sets the default language for new posts
|
||||||
|
"""
|
||||||
|
default_post_language_filename = \
|
||||||
|
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
||||||
|
try:
|
||||||
|
with open(default_post_language_filename, 'w+',
|
||||||
|
encoding='utf-8') as fp_lang:
|
||||||
|
fp_lang.write(language)
|
||||||
|
except OSError:
|
||||||
|
print('EX: Unable to write default post language ' +
|
||||||
|
default_post_language_filename)
|
||||||
|
|
||||||
|
|
||||||
|
def load_default_post_languages(base_dir: str) -> {}:
|
||||||
|
"""Returns a dictionary containing the default languages
|
||||||
|
for new posts for each account
|
||||||
|
"""
|
||||||
|
result = {}
|
||||||
|
for _, dirs, _ in os.walk(base_dir + '/accounts'):
|
||||||
|
for handle in dirs:
|
||||||
|
if not is_account_dir(handle):
|
||||||
|
continue
|
||||||
|
nickname = handle.split('@')[0]
|
||||||
|
domain = handle.split('@')[1]
|
||||||
|
default_post_language_filename = \
|
||||||
|
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
|
||||||
|
if not os.path.isfile(default_post_language_filename):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
with open(default_post_language_filename, 'r',
|
||||||
|
encoding='utf-8') as fp_lang:
|
||||||
|
result[nickname] = fp_lang.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: Unable to read default post language ' +
|
||||||
|
default_post_language_filename)
|
||||||
|
return result
|
||||||
|
|
|
@ -279,7 +279,8 @@ def html_new_post(edit_post_params: {},
|
||||||
reply_is_chat: bool, bold_reading: bool,
|
reply_is_chat: bool, bold_reading: bool,
|
||||||
dogwhistles: {},
|
dogwhistles: {},
|
||||||
min_images_for_accounts: [],
|
min_images_for_accounts: [],
|
||||||
default_month: int, default_year) -> str:
|
default_month: int, default_year: int,
|
||||||
|
default_post_language: str) -> str:
|
||||||
"""New post screen
|
"""New post screen
|
||||||
"""
|
"""
|
||||||
# get the json if this is an edited post
|
# get the json if this is an edited post
|
||||||
|
@ -796,9 +797,9 @@ def html_new_post(edit_post_params: {},
|
||||||
languages_dropdown += ' </select><br>'
|
languages_dropdown += ' </select><br>'
|
||||||
languages_dropdown = \
|
languages_dropdown = \
|
||||||
languages_dropdown.replace('<option value="' +
|
languages_dropdown.replace('<option value="' +
|
||||||
system_language + '">',
|
default_post_language + '">',
|
||||||
'<option value="' +
|
'<option value="' +
|
||||||
system_language +
|
default_post_language +
|
||||||
'" selected>')
|
'" selected>')
|
||||||
replies_section += \
|
replies_section += \
|
||||||
' <label class="labels">' + \
|
' <label class="labels">' + \
|
||||||
|
|
Loading…
Reference in New Issue