Repository: pwr-Solaar/Solaar

Issue:
Translation string contains two unnamed arguments
Two unnamed arguments that should be named. Only use unnamed arguments when it can't be confused, that is the string contains only a single argument.

The rationale for this is to be order agnostic, as some languages swap the order in some sentences. This can be tricky to get around for translators, but it is strictly speaking not a traditional bug. It is just extremely annoying.

- lib/solaar/listener.py:189




Discussion:
Yeah, I can see that this is a problem.
What's the best solution?    Is it using `format` or `%` with named arguments?  Or do format strings work?
This string was in a log message so it should not have been translatable.  The fix is thus easy.

Resolving patch:
diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py
--- a/lib/solaar/listener.py
+++ b/lib/solaar/listener.py
@@ -186,7 +186,7 @@ def _notifications_handler(self, n):
         # 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
--- a/lib/solaar/ui/pair_window.py
+++ b/lib/solaar/ui/pair_window.py
@@ -24,7 +24,7 @@
 
 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
--- 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<small>%s</small>' % _('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<small>%s</small>' % _('This receiver has %d pairing(s) remaining.') % pairings
+        paired_text += '\n<small>%s</small>' % (
+            ngettext('This receiver has %d pairing remaining.', 'This receiver has %d pairings remaining.', pairings) %
+            pairings
+        )
 
     panel._count.set_markup(paired_text)
 


Test patch: