Skip to content

Commit

Permalink
Improve some en strings and enable 'last synced' translations (#373)
Browse files Browse the repository at this point in the history
* Improve some english strings

* Enable translation of last synced indicator

* Use self.tr instead of QCoreApplication.translate

* Update test strings
  • Loading branch information
sanjacob authored Sep 18, 2024
1 parent 0ac19d4 commit 9e16bb3
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 70 deletions.
5 changes: 1 addition & 4 deletions blackboard_sync/qt/LoginWebView.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
# MA 02110-1301, USA.

import webbrowser
from functools import partial
from threading import Timer
from requests.cookies import RequestsCookieJar

from PyQt6.QtCore import QCoreApplication
from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject, QUrl
from PyQt6.QtWidgets import QWidget, QPushButton, QLabel
from PyQt6.QtNetwork import QNetworkCookie
Expand All @@ -30,7 +28,6 @@
from .assets import load_ui, get_theme_icon, AppIcon


tr = partial(QCoreApplication.translate, 'LoginWebView')
WATCHDOG_DELAY = 30


Expand Down Expand Up @@ -125,7 +122,7 @@ def slot_help(self) -> None:
webbrowser.open(self.help_url)

def show_help(self) -> None:
self.status.setText(tr(
self.status.setText(self.tr(
"Trouble logging in? Press the help button to let us know."
))
self.help_button.setVisible(True)
Expand Down
32 changes: 28 additions & 4 deletions blackboard_sync/qt/LoginWebView.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</size>
</property>
<property name="windowTitle">
<string>Log in to Blackboard</string>
<string>Log in to Blackboard Learn</string>
</property>
<property name="windowIcon">
<iconset>
Expand Down Expand Up @@ -68,21 +68,38 @@
<layout class="QHBoxLayout" name="toolbar">
<item>
<widget class="QToolButton" name="back_button">
<property name="accessibleName">
<string>Go back</string>
</property>
<property name="text">
<string>...</string>
<string/>
</property>
<property name="icon">
<iconset theme="edit-undo">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="home_button">
<property name="accessibleName">
<string>Go to start</string>
</property>
<property name="text">
<string>...</string>
<string/>
</property>
<property name="icon">
<iconset theme="go-home">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
<size>
Expand All @@ -107,8 +124,15 @@
</item>
<item>
<widget class="QToolButton" name="help_button">
<property name="accessibleName">
<string>Report issue</string>
</property>
<property name="text">
<string>...</string>
<string/>
</property>
<property name="icon">
<iconset theme="help-about">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="iconSize">
<size>
Expand Down
6 changes: 4 additions & 2 deletions blackboard_sync/qt/SettingsWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def username(self) -> str:
@username.setter
def username(self, username: str) -> None:
if username:
self.current_session_label.setText(f"Logged in as {username}")
self.current_session_label.setText(
self.tr("Logged in as ") + username)
else:
self.current_session_label.setText("Not currently logged in")
self.current_session_label.setText(
self.tr("Not currently logged in"))
12 changes: 6 additions & 6 deletions blackboard_sync/qt/SettingsWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</font>
</property>
<property name="text">
<string>Download Location</string>
<string>Download location</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -89,7 +89,7 @@
</font>
</property>
<property name="text">
<string>Change Location</string>
<string>Change location</string>
</property>
</widget>
</item>
Expand All @@ -102,7 +102,7 @@
</font>
</property>
<property name="text">
<string>Sync Every</string>
<string>Sync every</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -143,7 +143,7 @@
</font>
</property>
<property name="text">
<string>User Session</string>
<string>User session</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -174,7 +174,7 @@
</font>
</property>
<property name="text">
<string>Log Out</string>
<string>Log out</string>
</property>
</widget>
</item>
Expand All @@ -187,7 +187,7 @@
</font>
</property>
<property name="text">
<string>Initial Setup</string>
<string>Initial setup</string>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions blackboard_sync/qt/SetupWizard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</size>
</property>
<property name="windowTitle">
<string>BlackboardSync Setup</string>
<string>Setup</string>
</property>
<property name="windowIcon">
<iconset>
Expand Down Expand Up @@ -54,7 +54,7 @@
</font>
</property>
<property name="text">
<string>You are a few steps away from syncing your Blackboard content straight to your device!</string>
<string>You are a few steps away from syncing your Blackboard Learn content straight to your device!</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
Expand Down
23 changes: 9 additions & 14 deletions blackboard_sync/qt/SyncTrayIcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

from functools import partial
from datetime import datetime

from PyQt6.QtGui import QAction
from PyQt6.QtCore import pyqtSignal, QObject
from PyQt6.QtWidgets import QMenu, QSystemTrayIcon

from PyQt6.QtCore import QCoreApplication

from .assets import logo, get_theme_icon, AppIcon
from .utils import time_ago
from .notification import Event, TrayMessages

tr = partial(QCoreApplication.translate, 'SyncTrayMenu')


class SyncTrayMenu(QMenu):

Expand All @@ -47,27 +42,27 @@ def _init_ui(self) -> None:
close_icon = get_theme_icon(AppIcon.EXIT)
open_dir_icon = get_theme_icon(AppIcon.OPEN)

self.refresh = QAction(tr("Sync now"))
self.refresh = QAction(self.tr("Sync now"))
self.refresh.setIcon(sync_icon)
self.addAction(self.refresh)

self.open_dir = QAction(tr("Open downloads"))
self.open_dir = QAction(self.tr("Open downloads"))
self.open_dir.setIcon(open_dir_icon)
self.addAction(self.open_dir)

self.preferences = QAction(tr("Preferences"))
self.preferences = QAction(self.tr("Preferences"))
self.addAction(self.preferences)

self.addSeparator()

self._status = QAction(tr("You haven't logged in"))
self._status = QAction(self.tr("You haven't logged in"))
self._status.setEnabled(False)
self.addAction(self._status)

self.reset_setup = QAction(tr("Redo Setup"))
self.reset_setup = QAction(self.tr("Setup"))
self.addAction(self.reset_setup)

self.quit = QAction(tr("Quit"))
self.quit = QAction(self.tr("Quit"))
self.quit.setIcon(close_icon)
self.addAction(self.quit)

Expand All @@ -80,18 +75,18 @@ def set_logged_in(self, logged_in: bool) -> None:
if logged_in:
self.set_last_synced(self._last_synced)
else:
self._status.setText(tr("Not Logged In"))
self._status.setText(self.tr("Not logged in"))

def set_last_synced(self, last_synced: datetime | None) -> None:
self._last_synced = last_synced
human_ago = time_ago(last_synced) if last_synced else "Never"
self._status.setText(tr("Last Synced: ") + human_ago)
self._status.setText(self.tr("Last synced: ") + human_ago)

def set_currently_syncing(self, syncing: bool) -> None:
self.refresh.setEnabled(not syncing)

if syncing:
self._status.setText(tr("Downloading now..."))
self._status.setText(self.tr("Downloading now..."))


class SyncTrayIcon(QSystemTrayIcon):
Expand Down
18 changes: 7 additions & 11 deletions blackboard_sync/qt/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

import webbrowser
from pathlib import Path
from functools import partial

from PyQt6.QtCore import QCoreApplication, QObject
from PyQt6.QtCore import QObject
from PyQt6.QtWidgets import QMessageBox, QFileDialog

from .assets import logo


tr = partial(QCoreApplication.translate, 'Dialogs')


class DirDialog(QFileDialog):
"""Open the file dialog in directory mode."""
def init(self) -> None:
Expand All @@ -46,8 +42,8 @@ def __init__(self) -> None:

def redownload_dialog(self) -> bool:
q = QMessageBox()
q.setText(tr("Should BlackboardSync redownload all files?"))
q.setInformativeText(tr(
q.setText(self.tr("Do you wish to redownload all files?"))
q.setInformativeText(self.tr(
"Answer no if you intend to move all past downloads manually"
" (Recommended)."
))
Expand All @@ -61,10 +57,10 @@ def redownload_dialog(self) -> bool:

def uni_not_supported_dialog(self, url: str) -> None:
q = QMessageBox()
q.setText(tr(
q.setText(self.tr(
"Unfortunately, your university is not yet supported"
))
q.setInformativeText(tr(
q.setInformativeText(self.tr(
"You can help us provide support for it by visiting our website, "
"which you can access by pressing the help button."
))
Expand All @@ -79,10 +75,10 @@ def uni_not_supported_dialog(self, url: str) -> None:

def login_error_dialog(self, url: str) -> None:
q = QMessageBox()
q.setText(tr(
q.setText(self.tr(
"There was an issue logging you in"
))
q.setInformativeText(tr(
q.setInformativeText(self.tr(
"Please try again later, and if the error persists"
" contact our support by pressing the button below."
))
Expand Down
16 changes: 7 additions & 9 deletions blackboard_sync/qt/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

from functools import partial
from typing import NamedTuple
from enum import Enum, IntEnum, auto

from PyQt6.QtWidgets import QSystemTrayIcon
from PyQt6.QtCore import QCoreApplication, QObject
tr = partial(QCoreApplication.translate, 'TrayMessages')
from PyQt6.QtCore import QObject


class Event(Enum):
Expand Down Expand Up @@ -55,18 +53,18 @@ def __init__(self) -> None:

self.messages = {
Event.UPDATE_AVAILABLE: SyncTrayMsg(
tr('An update is available'),
tr('You can update the app from your digital store'),
self.tr('An update is available'),
self.tr('You can update the app from your digital store'),
Severity.INFORMATION.value, Duration.SHORT
),
Event.DOWNLOAD_ERROR: SyncTrayMsg(
tr('The download could not be completed'),
tr('There was an error while downloading your content'),
self.tr('The download could not be completed'),
self.tr('There was an error while downloading your content'),
Severity.WARNING.value, Duration.LONG
),
Event.APP_RUNNING: SyncTrayMsg(
tr('The app is running in the background'),
tr('Click the tray icon to manage your downloads'),
self.tr('The app is running in the background'),
self.tr('Click the tray icon to manage your downloads'),
Severity.INFORMATION.value, Duration.LONG
)
}
Expand Down
Loading

0 comments on commit 9e16bb3

Please sign in to comment.