Philipp Hörist pushed to branch master at gajim / gajim
Commits: 2a0cd556 by wurstsalat at 2022-10-05T13:55:42+00:00 imprv: MessageRow: Set text direction for RTL text
Fixes #11148
- - - - -
2 changed files:
- gajim/common/i18n.py - gajim/gtk/conversation/rows/message.py
Changes:
===================================== gajim/common/i18n.py ===================================== @@ -107,21 +107,19 @@ def get_short_lang_code(lang: Optional[str] = None) -> str: return lang[:2]
-def paragraph_direction_mark(text: str) -> str: +def is_rtl_text(text: str) -> bool: ''' Determine paragraph writing direction according to http://www.unicode.org/reports/tr9/#The_Paragraph_Level - - Returns either Unicode LTR mark or RTL mark. ''' for char in text: bidi = unicodedata.bidirectional(char) if bidi == 'L': - return '\u200E' + return False if bidi in ('AL', 'R'): - return '\u200F' + return True
- return '\u200E' + return False
def Q_(text: str) -> str:
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -44,6 +44,7 @@ from gajim.common.helpers import message_needs_highlight from gajim.common.helpers import to_user_string from gajim.common.i18n import _ +from gajim.common.i18n import is_rtl_text from gajim.common.i18n import Q_ from gajim.common.modules.contacts import GroupchatContact from gajim.common.types import ChatContactT @@ -194,6 +195,10 @@ def __init__(self, self._bottom_box = Gtk.Box(spacing=6) self._bottom_box.add(self._message_widget)
+ if is_rtl_text(text): + self._bottom_box.set_halign(Gtk.Align.END) + self._message_widget.set_direction(Gtk.TextDirection.RTL) + more_menu_button = MoreMenuButton(self, self._contact, name) more_menu_button.set_hexpand(True) more_menu_button.set_halign(Gtk.Align.END) @@ -443,6 +448,13 @@ def set_retracted(self, text: str) -> None: self._message_widget.destroy() self._message_widget = MessageWidget(self._account) self._bottom_box.pack_start(self._message_widget, True, True, 0) + if is_rtl_text(text): + self._bottom_box.set_halign(Gtk.Align.END) + self._message_widget.set_direction(Gtk.TextDirection.RTL) + else: + self._bottom_box.set_halign(Gtk.Align.FILL) + self._message_widget.set_direction(Gtk.TextDirection.LTR) + self._message_widget.add_with_styling(text) self.get_style_context().add_class('retracted-message')
@@ -450,6 +462,13 @@ def set_correction(self, text: str, nickname: Optional[str]) -> None: if not isinstance(self._message_widget, PreviewWidget): self._message_widget.add_with_styling(text, nickname)
+ if is_rtl_text(text): + self._bottom_box.set_halign(Gtk.Align.END) + self._message_widget.set_direction(Gtk.TextDirection.RTL) + else: + self._bottom_box.set_halign(Gtk.Align.FILL) + self._message_widget.set_direction(Gtk.TextDirection.LTR) + self._has_receipt = False self._message_icons.set_receipt_icon_visible(False) self._message_icons.set_correction_icon_visible(True)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/2a0cd556b4bd40906b233211fbdd2908b...