summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2021-11-12 20:10:57 +0100
committerjvoisin2021-11-12 20:10:57 +0100
commit0c91ac7367ba3a859a7ba08d4ca586538748a5c4 (patch)
tree53f63e8ade2ae0d2133f4c47cee788968892e1d5
parent708841f9f54369ce11730666ee3f3b7521a0fa71 (diff)
Implement code for internationalization
-rw-r--r--nautilus/mat2.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/nautilus/mat2.py b/nautilus/mat2.py
index 9ed6c2d..11e6986 100644
--- a/nautilus/mat2.py
+++ b/nautilus/mat2.py
@@ -16,6 +16,7 @@ import queue
16import threading 16import threading
17from typing import Tuple, Optional, List 17from typing import Tuple, Optional, List
18from urllib.parse import unquote 18from urllib.parse import unquote
19import gettext
19 20
20import gi 21import gi
21gi.require_version('Nautilus', '3.0') 22gi.require_version('Nautilus', '3.0')
@@ -25,6 +26,8 @@ from gi.repository import Nautilus, GObject, Gtk, Gio, GLib, GdkPixbuf
25 26
26from libmat2 import parser_factory 27from libmat2 import parser_factory
27 28
29_ = gettext.gettext
30
28 31
29def _remove_metadata(fpath) -> Tuple[bool, Optional[str]]: 32def _remove_metadata(fpath) -> Tuple[bool, Optional[str]]:
30 """ This is a simple wrapper around libmat2, because it's 33 """ This is a simple wrapper around libmat2, because it's
@@ -51,11 +54,11 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
51 self.infobar.set_show_close_button(True) 54 self.infobar.set_show_close_button(True)
52 self.infobar_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) 55 self.infobar_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
53 56
54 btn = Gtk.Button("Show") 57 btn = Gtk.Button(_("Show"))
55 btn.connect("clicked", self.__cb_show_failed) 58 btn.connect("clicked", self.__cb_show_failed)
56 self.infobar_hbox.pack_end(btn, False, False, 0) 59 self.infobar_hbox.pack_end(btn, False, False, 0)
57 60
58 infobar_msg = Gtk.Label("Failed to clean some items") 61 infobar_msg = Gtk.Label(_("Failed to clean some items"))
59 self.infobar_hbox.pack_start(infobar_msg, False, False, 0) 62 self.infobar_hbox.pack_start(infobar_msg, False, False, 0)
60 63
61 self.infobar.get_content_area().pack_start(self.infobar_hbox, True, True, 0) 64 self.infobar.get_content_area().pack_start(self.infobar_hbox, True, True, 0)
@@ -90,9 +93,9 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
90 window = Gtk.Window() 93 window = Gtk.Window()
91 headerbar = Gtk.HeaderBar() 94 headerbar = Gtk.HeaderBar()
92 window.set_titlebar(headerbar) 95 window.set_titlebar(headerbar)
93 headerbar.props.title = "Metadata removal failed" 96 headerbar.props.title = _("Metadata removal failed")
94 97
95 close_buton = Gtk.Button("Close") 98 close_buton = Gtk.Button(_("Close"))
96 close_buton.connect("clicked", lambda _: window.close()) 99 close_buton.connect("clicked", lambda _: window.close())
97 headerbar.pack_end(close_buton) 100 headerbar.pack_end(close_buton)
98 101
@@ -107,9 +110,9 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
107 """ Validate if a given file FileInfo `fileinfo` can be processed. 110 """ Validate if a given file FileInfo `fileinfo` can be processed.
108 Returns a boolean, and a textreason why""" 111 Returns a boolean, and a textreason why"""
109 if fileinfo.get_uri_scheme() != "file" or fileinfo.is_directory(): 112 if fileinfo.get_uri_scheme() != "file" or fileinfo.is_directory():
110 return False, "Not a file" 113 return False, _("Not a file")
111 elif not fileinfo.can_write(): 114 elif not fileinfo.can_write():
112 return False, "Not writeable" 115 return False, _("Not writeable")
113 return True, "" 116 return True, ""
114 117
115 def __create_treeview(self) -> Gtk.TreeView: 118 def __create_treeview(self) -> Gtk.TreeView:
@@ -120,7 +123,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
120 column_pixbuf = Gtk.TreeViewColumn("Icon", renderer_pixbuf, pixbuf=0) 123 column_pixbuf = Gtk.TreeViewColumn("Icon", renderer_pixbuf, pixbuf=0)
121 treeview.append_column(column_pixbuf) 124 treeview.append_column(column_pixbuf)
122 125
123 for idx, name in enumerate(['File', 'Reason']): 126 for idx, name in enumerate([_('File'), _('Reason')]):
124 renderer_text = Gtk.CellRendererText() 127 renderer_text = Gtk.CellRendererText()
125 column_text = Gtk.TreeViewColumn(name, renderer_text, text=idx+1) 128 column_text = Gtk.TreeViewColumn(name, renderer_text, text=idx+1)
126 treeview.append_column(column_text) 129 treeview.append_column(column_text)
@@ -180,7 +183,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
180 return False 183 return False
181 184
182 progressbar.pulse() 185 progressbar.pulse()
183 progressbar.set_text("Cleaning %s" % fname) 186 progressbar.set_text(_("Cleaning %s") % fname)
184 progressbar.show_all() 187 progressbar.show_all()
185 self.infobar_hbox.show_all() 188 self.infobar_hbox.show_all()
186 self.infobar.show_all() 189 self.infobar.show_all()
@@ -202,7 +205,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
202 fpath = unquote(fileinfo.get_uri()[7:]) # `len('file://') = 7` 205 fpath = unquote(fileinfo.get_uri()[7:]) # `len('file://') = 7`
203 success, mtype = _remove_metadata(fpath) 206 success, mtype = _remove_metadata(fpath)
204 if not success: 207 if not success:
205 self.failed_items.append((fname, mtype, 'Unsupported/invalid')) 208 self.failed_items.append((fname, mtype, _('Unsupported/invalid')))
206 processing_queue.put(None) # signal that we processed all the files 209 processing_queue.put(None) # signal that we processed all the files
207 return True 210 return True
208 211
@@ -236,8 +239,8 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
236 239
237 item = Nautilus.MenuItem( 240 item = Nautilus.MenuItem(
238 name="mat2::Remove_metadata", 241 name="mat2::Remove_metadata",
239 label="Remove metadata", 242 label=_("Remove metadata"),
240 tip="Remove metadata" 243 tip=_("Remove metadata")
241 ) 244 )
242 item.connect('activate', self.__cb_menu_activate, files) 245 item.connect('activate', self.__cb_menu_activate, files)
243 246