Philipp Hörist pushed to branch master at gajim / gajim

Commits:

2 changed files:

Changes:

  • gajim/common/i18n.py
    ... ... @@ -107,21 +107,19 @@ def get_short_lang_code(lang: Optional[str] = None) -> str:
    107 107
         return lang[:2]
    
    108 108
     
    
    109 109
     
    
    110
    -def paragraph_direction_mark(text: str) -> str:
    
    110
    +def is_rtl_text(text: str) -> bool:
    
    111 111
         '''
    
    112 112
         Determine paragraph writing direction according to
    
    113 113
         http://www.unicode.org/reports/tr9/#The_Paragraph_Level
    
    114
    -
    
    115
    -    Returns either Unicode LTR mark or RTL mark.
    
    116 114
         '''
    
    117 115
         for char in text:
    
    118 116
             bidi = unicodedata.bidirectional(char)
    
    119 117
             if bidi == 'L':
    
    120
    -            return '\u200E'
    
    118
    +            return False
    
    121 119
             if bidi in ('AL', 'R'):
    
    122
    -            return '\u200F'
    
    120
    +            return True
    
    123 121
     
    
    124
    -    return '\u200E'
    
    122
    +    return False
    
    125 123
     
    
    126 124
     
    
    127 125
     def Q_(text: str) -> str:
    

  • gajim/gtk/conversation/rows/message.py
    ... ... @@ -44,6 +44,7 @@
    44 44
     from gajim.common.helpers import message_needs_highlight
    
    45 45
     from gajim.common.helpers import to_user_string
    
    46 46
     from gajim.common.i18n import _
    
    47
    +from gajim.common.i18n import is_rtl_text
    
    47 48
     from gajim.common.i18n import Q_
    
    48 49
     from gajim.common.modules.contacts import GroupchatContact
    
    49 50
     from gajim.common.types import ChatContactT
    
    ... ... @@ -194,6 +195,10 @@ def __init__(self,
    194 195
             self._bottom_box = Gtk.Box(spacing=6)
    
    195 196
             self._bottom_box.add(self._message_widget)
    
    196 197
     
    
    198
    +        if is_rtl_text(text):
    
    199
    +            self._bottom_box.set_halign(Gtk.Align.END)
    
    200
    +            self._message_widget.set_direction(Gtk.TextDirection.RTL)
    
    201
    +
    
    197 202
             more_menu_button = MoreMenuButton(self, self._contact, name)
    
    198 203
             more_menu_button.set_hexpand(True)
    
    199 204
             more_menu_button.set_halign(Gtk.Align.END)
    
    ... ... @@ -443,6 +448,13 @@ def set_retracted(self, text: str) -> None:
    443 448
                 self._message_widget.destroy()
    
    444 449
                 self._message_widget = MessageWidget(self._account)
    
    445 450
                 self._bottom_box.pack_start(self._message_widget, True, True, 0)
    
    451
    +            if is_rtl_text(text):
    
    452
    +                self._bottom_box.set_halign(Gtk.Align.END)
    
    453
    +                self._message_widget.set_direction(Gtk.TextDirection.RTL)
    
    454
    +            else:
    
    455
    +                self._bottom_box.set_halign(Gtk.Align.FILL)
    
    456
    +                self._message_widget.set_direction(Gtk.TextDirection.LTR)
    
    457
    +
    
    446 458
             self._message_widget.add_with_styling(text)
    
    447 459
             self.get_style_context().add_class('retracted-message')
    
    448 460
     
    
    ... ... @@ -450,6 +462,13 @@ def set_correction(self, text: str, nickname: Optional[str]) -> None:
    450 462
             if not isinstance(self._message_widget, PreviewWidget):
    
    451 463
                 self._message_widget.add_with_styling(text, nickname)
    
    452 464
     
    
    465
    +            if is_rtl_text(text):
    
    466
    +                self._bottom_box.set_halign(Gtk.Align.END)
    
    467
    +                self._message_widget.set_direction(Gtk.TextDirection.RTL)
    
    468
    +            else:
    
    469
    +                self._bottom_box.set_halign(Gtk.Align.FILL)
    
    470
    +                self._message_widget.set_direction(Gtk.TextDirection.LTR)
    
    471
    +
    
    453 472
             self._has_receipt = False
    
    454 473
             self._message_icons.set_receipt_icon_visible(False)
    
    455 474
             self._message_icons.set_correction_icon_visible(True)