From fd02b33971dcb257aee1f83fcc85796510257537 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Fri, 31 Jul 2020 07:47:57 -0400 Subject: [PATCH] ui: use ngettext for translatable strings with number dependencies --- lib/solaar/listener.py | 2 +- lib/solaar/ui/pair_window.py | 9 ++++++--- lib/solaar/ui/window.py | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index f0b57563..84a020af 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -186,7 +186,7 @@ class ReceiverListener(_listener.EventsListener): # a device notification if not (0 < n.devnumber <= self.receiver.max_devices): if _log.isEnabledFor(_WARNING): - _log.warning(_('Unexpected device number (%s) in notification %s.' % (n.devnumber, n))) + _log.warning('Unexpected device number (%s) in notification %s.', n.devnumber, n) return already_known = n.devnumber in self.receiver diff --git a/lib/solaar/ui/pair_window.py b/lib/solaar/ui/pair_window.py index 27e5e6b0..153324fc 100644 --- a/lib/solaar/ui/pair_window.py +++ b/lib/solaar/ui/pair_window.py @@ -24,7 +24,7 @@ from logging import getLogger from gi.repository import GLib, Gtk from logitech_receiver.status import KEYS as _K -from solaar.i18n import _ +from solaar.i18n import _, ngettext from . import icons as _icons @@ -137,7 +137,7 @@ def _pairing_failed(assistant, receiver, error): elif str(error) == 'device not supported': text = _('A new device was detected, but it is not compatible with this receiver.') elif 'many' in str(error): - text = _('The receiver only supports %d paired device(s).') + text = _('More paired devices than receiver can support.') else: text = _('No further details are available about the error.') _create_page(assistant, Gtk.AssistantPageType.SUMMARY, header, 'dialog-error', text) @@ -205,7 +205,10 @@ def create(receiver): page_text = _('If the device is already turned on, turn if off and on again.') if receiver.remaining_pairings() and receiver.remaining_pairings() >= 0: - page_text += _('\n\nThis receiver has %d pairing(s) remaining.') % receiver.remaining_pairings() + page_text += ngettext( + '\n\nThis receiver has %d pairing remaining.', '\n\nThis receiver has %d pairings remaining.', + receiver.remaining_pairings() + ) % receiver.remaining_pairings() page_text += _('\nCancelling at this point will not use up a pairing.') page_intro = _create_page( diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index d6ae0fcb..2490006e 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -610,7 +610,10 @@ def _update_receiver_panel(receiver, panel, buttons, full=False): paired_text += '\n\n%s' % _('Only one device can be paired to this receiver.') pairings = receiver.remaining_pairings(False) if (pairings is not None and pairings >= 0): - paired_text += '\n%s' % _('This receiver has %d pairing(s) remaining.') % pairings + paired_text += '\n%s' % ( + ngettext('This receiver has %d pairing remaining.', 'This receiver has %d pairings remaining.', pairings) % + pairings + ) panel._count.set_markup(paired_text)