mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-06 01:17:32 +01:00
Idiomas
This commit is contained in:
@@ -106,12 +106,16 @@ class post(base_messages.basicMessage):
|
||||
def __init__(self, session: Any, title: str, caption: str, text: str = "", *args, **kwargs):
|
||||
self.session = session
|
||||
self.title = title
|
||||
self.message = postDialogs.Post(caption=caption, text=text, *args, **kwargs)
|
||||
langs = session.supported_languages
|
||||
display_langs = [l.name for l in langs]
|
||||
self.message = postDialogs.Post(caption=caption, text=text, languages=display_langs, *args, **kwargs)
|
||||
try:
|
||||
self.message.SetTitle(title)
|
||||
self.message.text.SetInsertionPoint(len(self.message.text.GetValue()))
|
||||
except Exception:
|
||||
pass
|
||||
# Set default language
|
||||
self.set_language(session.default_language)
|
||||
# Connect events for text processing and buttons
|
||||
widgetUtils.connect_event(self.message.text, widgetUtils.ENTERED_TEXT, self.text_processor)
|
||||
widgetUtils.connect_event(self.message.spoiler, widgetUtils.ENTERED_TEXT, self.text_processor)
|
||||
@@ -121,8 +125,32 @@ class post(base_messages.basicMessage):
|
||||
# Initial text processing to show character count
|
||||
self.text_processor()
|
||||
|
||||
def set_language(self, language_code=None):
|
||||
"""Set the language selection based on language code."""
|
||||
if language_code is None:
|
||||
language_code = languageHandler.curLang[:2]
|
||||
for idx, lang in enumerate(self.session.supported_languages):
|
||||
if lang.code == language_code:
|
||||
self.message.language.SetSelection(idx)
|
||||
return
|
||||
# If not found, select first item (Not set)
|
||||
self.message.language.SetSelection(0)
|
||||
|
||||
def get_language(self):
|
||||
"""Get the selected language code."""
|
||||
langs = self.session.supported_languages
|
||||
idx = self.message.language.GetSelection()
|
||||
if idx >= 0 and idx < len(langs):
|
||||
return langs[idx].code
|
||||
return None
|
||||
|
||||
def get_data(self):
|
||||
return self.message.get_payload()
|
||||
text, files, cw_text, lang_index = self.message.get_payload()
|
||||
langs = self.session.supported_languages
|
||||
lang_code = None
|
||||
if lang_index >= 0 and lang_index < len(langs):
|
||||
lang_code = langs[lang_index].code
|
||||
return text, files, cw_text, ([lang_code] if lang_code else [])
|
||||
|
||||
def text_processor(self, *args, **kwargs):
|
||||
text = self.message.text.GetValue()
|
||||
|
||||
@@ -12,9 +12,46 @@ from sessions import base
|
||||
from sessions import session_exceptions as Exceptions
|
||||
import output
|
||||
import application
|
||||
import languageHandler
|
||||
|
||||
log = logging.getLogger("sessions.blueskiSession")
|
||||
|
||||
|
||||
class Language:
|
||||
"""Simple language object with code and name attributes, mimicking Mastodon.py format."""
|
||||
def __init__(self, code: str, name: str):
|
||||
self.code = code
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return f"Language({self.code}, {self.name})"
|
||||
|
||||
|
||||
def get_supported_languages():
|
||||
"""Returns the list of supported languages with translated names."""
|
||||
return [
|
||||
Language("", _("Not set")),
|
||||
Language("en", _("English")),
|
||||
Language("es", _("Spanish")),
|
||||
Language("fr", _("French")),
|
||||
Language("de", _("German")),
|
||||
Language("it", _("Italian")),
|
||||
Language("pt", _("Portuguese")),
|
||||
Language("ja", _("Japanese")),
|
||||
Language("ko", _("Korean")),
|
||||
Language("zh", _("Chinese")),
|
||||
Language("ru", _("Russian")),
|
||||
Language("ar", _("Arabic")),
|
||||
Language("hi", _("Hindi")),
|
||||
Language("nl", _("Dutch")),
|
||||
Language("pl", _("Polish")),
|
||||
Language("tr", _("Turkish")),
|
||||
Language("uk", _("Ukrainian")),
|
||||
Language("ca", _("Catalan")),
|
||||
Language("eu", _("Basque")),
|
||||
Language("gl", _("Galician")),
|
||||
]
|
||||
|
||||
# Optional import of atproto. Code handles absence gracefully.
|
||||
try:
|
||||
from atproto import Client as AtpClient # type: ignore
|
||||
@@ -39,6 +76,8 @@ class Session(base.baseSession):
|
||||
self.char_limit = 300
|
||||
self.api = None
|
||||
self.poller = None
|
||||
self.supported_languages = get_supported_languages()
|
||||
self.default_language = languageHandler.curLang[:2]
|
||||
# Subscribe to pub/sub events from the poller
|
||||
pub.subscribe(self.on_notification, "blueski.notification_received")
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@ Utility functions for Bluesky session.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
log = logging.getLogger("sessions.blueski.utils")
|
||||
|
||||
url_re = re.compile(r'https?://[^\s<>\[\]()"\',]+[^\s<>\[\]()"\',.:;!?]')
|
||||
|
||||
|
||||
def g(obj, key, default=None):
|
||||
"""Helper to get attribute from dict or object."""
|
||||
@@ -254,6 +257,14 @@ def find_urls(post):
|
||||
if uri and uri not in urls:
|
||||
urls.append(uri)
|
||||
|
||||
# Also search plain text for URLs using regex (fallback)
|
||||
text = g(record, "text", "")
|
||||
if text:
|
||||
text_urls = url_re.findall(text)
|
||||
for u in text_urls:
|
||||
if u not in urls:
|
||||
urls.append(u)
|
||||
|
||||
return urls
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import wx
|
||||
|
||||
|
||||
class Post(wx.Dialog):
|
||||
def __init__(self, caption=_("Post"), text="", *args, **kwds):
|
||||
def __init__(self, caption=_("Post"), text="", languages=[], *args, **kwds):
|
||||
super(Post, self).__init__(parent=None, id=wx.ID_ANY, *args, **kwds)
|
||||
self.SetTitle(caption)
|
||||
main_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
@@ -43,10 +43,10 @@ class Post(wx.Dialog):
|
||||
|
||||
# Language (single optional)
|
||||
lang_row = wx.BoxSizer(wx.HORIZONTAL)
|
||||
lang_row.Add(wx.StaticText(self, label=_("Language")), 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 4)
|
||||
self.lang_choice = wx.ComboBox(self, wx.ID_ANY, choices=["", "en", "es", "fr", "de", "ja", "pt", "ru", "zh"], style=wx.CB_DROPDOWN | wx.CB_READONLY)
|
||||
self.lang_choice.SetSelection(0)
|
||||
lang_row.Add(self.lang_choice, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
lang_row.Add(wx.StaticText(self, label=_("&Language")), 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 4)
|
||||
self.language = wx.ComboBox(self, wx.ID_ANY, choices=languages, style=wx.CB_DROPDOWN | wx.CB_READONLY)
|
||||
self.language.SetSelection(0)
|
||||
lang_row.Add(self.language, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
main_sizer.Add(lang_row, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM, 6)
|
||||
|
||||
# Text actions (spellcheck, translate, autocomplete)
|
||||
@@ -113,14 +113,14 @@ class Post(wx.Dialog):
|
||||
def get_payload(self):
|
||||
text = self.text.GetValue().strip()
|
||||
cw_text = self.spoiler.GetValue().strip() if self.sensitive.GetValue() else None
|
||||
lang = self.lang_choice.GetValue().strip() or None
|
||||
lang_index = self.language.GetSelection()
|
||||
files = []
|
||||
for i in range(self.attach_list.GetItemCount()):
|
||||
files.append({
|
||||
"path": self.attach_list.GetItemText(i, 0),
|
||||
"alt": self.attach_list.GetItemText(i, 1),
|
||||
})
|
||||
return text, files, cw_text, (lang and [lang] or [])
|
||||
return text, files, cw_text, lang_index
|
||||
|
||||
|
||||
class viewPost(wx.Dialog):
|
||||
|
||||
Reference in New Issue
Block a user