Improve support for right-to-left languages

main
Bob Mottram 2023-09-10 11:12:39 +01:00
parent b78e38a26c
commit ea21eeb52d
6 changed files with 55 additions and 22 deletions

View File

@ -1,6 +1,8 @@
@charset "UTF-8";
:root {
--text-justify: left;
--language-direction: ltr;
--hashtag-margin: 2%;
--hashtag-size1: 30px;
--hashtag-size2: 40px;
@ -289,6 +291,10 @@ mark {
font-weight: bold;
}
details {
direction: var(--language-direction);
}
.diff_add {
color: var(--diff-add);
}
@ -518,7 +524,7 @@ a:focus {
}
.buttonprev {
float: left;
float: var(--text-justify);
width: 10%;
-ms-transform: translateY(30%);
transform: translateY(30%);
@ -653,7 +659,7 @@ a:focus {
hyphens: auto;
text-wrap: pretty;
text-align: justify;
direction: ltr;
direction: var(--language-direction);
}
.message_rtl {
@ -823,7 +829,7 @@ a:focus {
.skill-title {
margin-left: 25%;
text-align: left;
text-align: var(--text-justify);
font-size: var(--font-size2);
font-family: 'Arial, Helvetica, sans-serif';
font-weight: bold;
@ -856,11 +862,13 @@ input[type=number] {
resize: vertical;
font-size: var(--font-size-header);
font-family: 'Arial, Helvetica, sans-serif';
float: var(--text-justify);
}
.labels {
font-size: var(--font-size);
font-family: 'Arial, Helvetica, sans-serif';
float: var(--text-justify);
}
.transparent {
@ -1178,6 +1186,7 @@ h3 {
font-family: var(--header-font);
font-size: var(--font-size);
color: var(--title-color);
float: var(--text-justify);
}
.container img.postScopeIcon {
float: none;
@ -1794,6 +1803,7 @@ h3 {
font-family: 'Arial, Helvetica, sans-serif';
background-color: var(--main-bg-color-reply);
color: var(--main-fg-color);
direction: var(--language-direction);
}
input[type=button], input[type=submit] {
background-color: var(--button-background);
@ -1910,6 +1920,7 @@ h3 {
transform: scale(2);
padding: 10px;
margin: 20px 30px;
float: var(--text-justify);
}
input[type=radio]
{
@ -2007,6 +2018,7 @@ h3 {
font-family: var(--header-font);
font-size: var(--font-size-mobile);
color: var(--title-color);
float: var(--text-justify);
}
.container img.attachment {
width: 125%;
@ -2623,6 +2635,7 @@ h3 {
font-family: 'Arial, Helvetica, sans-serif';
background-color: var(--main-bg-color-reply);
color: var(--main-fg-color);
direction: var(--language-direction);
}
input[type=button], input[type=submit] {
background-color: var(--button-background);
@ -2739,6 +2752,7 @@ h3 {
transform: scale(2);
padding: 20px;
margin: 30px 40px;
float: var(--text-justify);
}
input[type=radio]
{
@ -2834,6 +2848,7 @@ h3 {
font-family: var(--header-font);
font-size: var(--font-size-tiny);
color: var(--title-color);
float: var(--text-justify);
}
.container img.attachment {
width: 125%;
@ -3450,6 +3465,7 @@ h3 {
font-family: 'Arial, Helvetica, sans-serif';
background-color: var(--main-bg-color-reply);
color: var(--main-fg-color);
direction: var(--language-direction);
}
input[type=button], input[type=submit] {
background-color: var(--button-background);
@ -3567,6 +3583,7 @@ h3 {
padding: 20px;
margin: 30px 40px;
width: 10px;
float: var(--text-justify);
}
input[type=radio]
{

View File

@ -19,6 +19,7 @@ from utils import local_actor_url
from utils import remove_html
from utils import text_in_file
from utils import remove_eol
from utils import language_right_to_left
from shutil import copyfile
from shutil import make_archive
from shutil import unpack_archive
@ -327,11 +328,13 @@ def set_css_param(css: str, param: str, value: str) -> str:
def _set_theme_from_dict(base_dir: str, name: str,
theme_params: {}, bg_params: {},
allow_local_network_access: bool) -> None:
allow_local_network_access: bool,
system_language: str) -> None:
"""Uses a dictionary to set a theme
"""
if name:
_set_theme_in_config(base_dir, name)
rtl = language_right_to_left(system_language)
theme_files = _get_theme_files()
for filename in theme_files:
# check for custom css within the theme directory
@ -387,6 +390,12 @@ def _set_theme_from_dict(base_dir: str, name: str,
_set_publish_button_at_top(base_dir, False)
continue
css = set_css_param(css, param_name, param_value)
# set the text direction
if rtl:
css = set_css_param(css, 'text-justify', 'right')
css = set_css_param(css, 'language-direction', 'rtl')
filename = base_dir + '/' + filename
with open(filename, 'w+', encoding='utf-8') as cssfile:
cssfile.write(css)
@ -549,7 +558,8 @@ def reset_theme_designer_settings(base_dir: str) -> None:
def _read_variables_file(base_dir: str, theme_name: str,
variables_file: str,
allow_local_network_access: bool) -> None:
allow_local_network_access: bool,
system_language: str) -> None:
"""Reads variables from a file in the theme directory
"""
theme_params = load_json(variables_file, 0)
@ -571,10 +581,11 @@ def _read_variables_file(base_dir: str, theme_name: str,
"search": "jpg"
}
_set_theme_from_dict(base_dir, theme_name, theme_params, bg_params,
allow_local_network_access)
allow_local_network_access, system_language)
def _set_theme_default(base_dir: str, allow_local_network_access: bool):
def _set_theme_default(base_dir: str, allow_local_network_access: bool,
system_language: str):
name = 'default'
_remove_theme(base_dir)
_set_theme_in_config(base_dir, name)
@ -582,7 +593,8 @@ def _set_theme_default(base_dir: str, allow_local_network_access: bool):
variables_file = base_dir + '/theme/' + name + '/theme.json'
if os.path.isfile(variables_file):
_read_variables_file(base_dir, name, variables_file,
allow_local_network_access)
allow_local_network_access,
system_language)
else:
bg_params = {
"login": "jpg",
@ -601,7 +613,8 @@ def _set_theme_default(base_dir: str, allow_local_network_access: bool):
"search-banner-height-mobile": "15vh"
}
_set_theme_from_dict(base_dir, name, theme_params, bg_params,
allow_local_network_access)
allow_local_network_access,
system_language)
def _set_theme_fonts(base_dir: str, theme_name: str) -> None:
@ -886,14 +899,16 @@ def set_theme(base_dir: str, name: str, domain: str,
if not result:
# default
_set_theme_default(base_dir, allow_local_network_access)
_set_theme_default(base_dir, allow_local_network_access,
system_language)
result = True
# read theme settings from a json file in the theme directory
variables_file = base_dir + '/theme/' + name + '/theme.json'
if os.path.isfile(variables_file):
_read_variables_file(base_dir, name, variables_file,
allow_local_network_access)
allow_local_network_access,
system_language)
if dyslexic_font:
_set_dyslexic_font(base_dir)
@ -918,6 +933,7 @@ def set_theme(base_dir: str, name: str, domain: str,
_copy_theme_help_files(base_dir, name, system_language)
_set_theme_in_config(base_dir, name)
_set_clear_cache_flag(base_dir)
return result

View File

@ -4531,3 +4531,12 @@ def ap_proxy_type(json_object: {}) -> str:
if isinstance(proxy_dict['protocol'], str):
return proxy_dict['protocol']
return None
def language_right_to_left(language: str) -> bool:
"""is the given language written from right to left?
"""
rtl_languages = ('ar', 'fa', 'he')
if language in rtl_languages:
return True
return False

View File

@ -23,11 +23,11 @@ from utils import remove_domain_port
from utils import acct_dir
from utils import local_actor_url
from utils import replace_users_with_at
from utils import language_right_to_left
from happening import get_todays_events
from happening import get_calendar_events
from happening import get_todays_events_icalendar
from happening import get_month_events_icalendar
from webapp_utils import language_right_to_left
from webapp_utils import get_banner_file
from webapp_utils import set_custom_background
from webapp_utils import html_header_with_external_style

View File

@ -69,6 +69,7 @@ from utils import get_domain_from_actor
from utils import acct_dir
from utils import local_actor_url
from utils import is_unlisted_post
from utils import language_right_to_left
from content import replace_remote_hashtags
from content import detect_dogwhistles
from content import create_edits_html
@ -84,7 +85,6 @@ from content import switch_words
from person import is_person_snoozed
from person import get_person_avatar_url
from webapp_utils import get_buy_links
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

View File

@ -2176,15 +2176,6 @@ def text_mode_browser(ua_str: str) -> bool:
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
def get_default_path(media_instance: bool, blogs_instance: bool,
nickname: str) -> str:
"""Returns the default timeline