[meld] Fix multiple-substitution i18n strings to used named arguments (#557)



commit 3305e583dd38d8f03db6beebd3115999f1167dbf
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Mar 6 08:12:39 2021 +1000

    Fix multiple-substitution i18n strings to used named arguments (#557)

 meld/dirdiff.py      | 22 +++++++++++++---------
 meld/style.py        |  5 +++--
 meld/ui/statusbar.py |  5 +++--
 meld/vc/git.py       | 23 ++++++++++++++---------
 meld/vcview.py       |  2 +-
 5 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 6ba5acc5..0d5e1c59 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -775,7 +775,8 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
             sel = t.get_selection()
             sel.unselect_all()
 
-        yield _("[%s] Scanning %s") % (self.label_text, "")
+        yield _('[{label}] Scanning {folder}').format(
+            label=self.label_text, folder='')
         prefixlen = 1 + len(
             self.model.value_path(self.model.get_iter(rootpath), 0))
         symlinks_followed = set()
@@ -798,8 +799,8 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
             if not any(os.path.isdir(root) for root in roots):
                 continue
 
-            yield _("[%s] Scanning %s") % (
-                self.label_text, roots[0][prefixlen:])
+            yield _('[{label}] Scanning {folder}').format(
+                label=self.label_text, folder=roots[0][prefixlen:])
             differences = False
             encoding_errors = []
 
@@ -938,7 +939,7 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         self.treeview[0].expand_to_path(Gtk.TreePath(("0",)))
         for path in sorted(expanded):
             self.treeview[0].expand_to_path(Gtk.TreePath(path))
-        yield _("[%s] Done") % self.label_text
+        yield _('[{label}] Done').format(label=self.label_text)
 
         self._scan_in_progress -= 1
         self.force_cursor_recalculate = True
@@ -1007,7 +1008,10 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         formatted_entries = [[] for i in range(self.num_panes)]
         for pane, root, f1, f2 in shadowed_entries:
             paths = [os.path.join(root, f) for f in (f1, f2)]
-            entry_str = _("“%s” hidden by “%s”") % (paths[0], paths[1])
+            entry_str = _("“{first_file}” hidden by “{second_file}”").format(
+                first_file=paths[0],
+                second_file=paths[1],
+            )
             formatted_entries[pane].append(entry_str)
 
         if invalid_filenames or shadowed_entries:
@@ -1079,10 +1083,10 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
             except (OSError, IOError, shutil.Error) as err:
                 misc.error_dialog(
                     _("Error copying file"),
-                    _("Couldn’t copy %s\nto %s.\n\n%s") % (
-                        GLib.markup_escape_text(src),
-                        GLib.markup_escape_text(dst),
-                        GLib.markup_escape_text(str(err)),
+                    _("Couldn’t copy {source}\nto {dest}.\n\n{error}").format(
+                        source=GLib.markup_escape_text(src),
+                        dest=GLib.markup_escape_text(dst),
+                        error=GLib.markup_escape_text(str(err)),
                     )
                 )
 
diff --git a/meld/style.py b/meld/style.py
index b45cffc4..f22cce14 100644
--- a/meld/style.py
+++ b/meld/style.py
@@ -86,9 +86,10 @@ def colour_lookup_with_fallback(name: str, attribute: str) -> Gdk.RGBA:
 
     if not style_attr:
         import sys
+        style_detail = f'{name}-{attribute}'
         print(_(
-            "Couldn’t find colour scheme details for %s-%s; "
-            "this is a bad install") % (name, attribute), file=sys.stderr)
+            "Couldn’t find colour scheme details for {}; "
+            "this is a bad install").format(style_detail), file=sys.stderr)
         sys.exit(1)
 
     colour = Gdk.RGBA()
diff --git a/meld/ui/statusbar.py b/meld/ui/statusbar.py
index da275ae2..5ccdae43 100644
--- a/meld/ui/statusbar.py
+++ b/meld/ui/statusbar.py
@@ -122,7 +122,7 @@ class MeldStatusBar(Gtk.Statusbar):
     )
 
     # Abbreviation for line, column so that it will fit in the status bar
-    _line_column_text = _("Ln %i, Col %i")
+    _line_column_text = _("Ln {line}, Col {column}")
 
     def __init__(self):
         super().__init__()
@@ -203,7 +203,8 @@ class MeldStatusBar(Gtk.Statusbar):
 
         def format_cursor_position(binding, cursor):
             line, offset = cursor
-            return self._line_column_text % (line + 1, offset + 1)
+            return self._line_column_text.format(
+                line=line + 1, column=offset + 1)
 
         button = MeldStatusMenuButton()
         self.bind_property(
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 08d384f6..b2dd0ee2 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -86,13 +86,17 @@ class Vc(_vc.Vc):
         unpushed_commits = sum(len(v) for v in branch_refs.values())
         if unpushed_commits:
             if unpushed_branches > 1:
-                # Translators: First %s is replaced by translated "%d unpushed
-                # commits", second %s is replaced by translated "%d branches"
-                label = _("%s in %s") % (
-                    ngettext("%d unpushed commit", "%d unpushed commits",
-                             unpushed_commits) % unpushed_commits,
-                    ngettext("%d branch", "%d branches",
-                             unpushed_branches) % unpushed_branches)
+                # Translators: First element is replaced by translated "%d
+                # unpushed commits", second element is replaced by translated
+                # "%d branches"
+                label = _("{unpushed_commits} in {unpushed_branches}").format(
+                    unpushed_commits=ngettext(
+                        "%d unpushed commit", "%d unpushed commits",
+                        unpushed_commits) % unpushed_commits,
+                    unpushed_branches=ngettext(
+                        "%d branch", "%d branches",
+                        unpushed_branches) % unpushed_branches,
+                )
             else:
                 # Translators: These messages cover the case where there is
                 # only one branch, and are not part of another message.
@@ -336,8 +340,9 @@ class Vc(_vc.Vc):
                 # Git entries can't be MISSING; that's just an unstaged REMOVED
                 self._add_missing_cache_entry(path, state)
                 if old_mode != new_mode:
-                    msg = _("Mode changed from %s to %s" %
-                            (old_mode, new_mode))
+                    msg = _(
+                        "Mode changed from {old_mode} to {new_mode}".format(
+                            old_mode=old_mode, new_mode=new_mode))
                     tree_meta_cache[path].append(msg)
                 collection = unstaged if new_sha == NULL_SHA else staged
                 collection.add(path)
diff --git a/meld/vcview.py b/meld/vcview.py
index cee2e725..4a507727 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -408,7 +408,7 @@ class VcView(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
     def recompute_label(self):
         self.label_text = os.path.basename(self.location)
         # TRANSLATORS: This is the location of the directory being viewed
-        self.tooltip_text = _("%s: %s") % (_("Location"), self.location)
+        self.tooltip_text = _("Location: {path}").format(path=self.location)
         self.label_changed.emit(self.label_text, self.tooltip_text)
 
     def _search_recursively_iter(self, start_path, replace=False):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]