Commit 0c91ac73 authored by jvoisin's avatar jvoisin
Browse files

Implement code for internationalization

parent 708841f9
Pipeline #68635 failed with stages
in 37 seconds
......@@ -16,6 +16,7 @@ import queue
import threading
from typing import Tuple, Optional, List
from urllib.parse import unquote
import gettext
import gi
gi.require_version('Nautilus', '3.0')
......@@ -25,6 +26,8 @@ from gi.repository import Nautilus, GObject, Gtk, Gio, GLib, GdkPixbuf
from libmat2 import parser_factory
_ = gettext.gettext
def _remove_metadata(fpath) -> Tuple[bool, Optional[str]]:
""" This is a simple wrapper around libmat2, because it's
......@@ -51,11 +54,11 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
self.infobar.set_show_close_button(True)
self.infobar_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
btn = Gtk.Button("Show")
btn = Gtk.Button(_("Show"))
btn.connect("clicked", self.__cb_show_failed)
self.infobar_hbox.pack_end(btn, False, False, 0)
infobar_msg = Gtk.Label("Failed to clean some items")
infobar_msg = Gtk.Label(_("Failed to clean some items"))
self.infobar_hbox.pack_start(infobar_msg, False, False, 0)
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
window = Gtk.Window()
headerbar = Gtk.HeaderBar()
window.set_titlebar(headerbar)
headerbar.props.title = "Metadata removal failed"
headerbar.props.title = _("Metadata removal failed")
close_buton = Gtk.Button("Close")
close_buton = Gtk.Button(_("Close"))
close_buton.connect("clicked", lambda _: window.close())
headerbar.pack_end(close_buton)
......@@ -107,9 +110,9 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
""" Validate if a given file FileInfo `fileinfo` can be processed.
Returns a boolean, and a textreason why"""
if fileinfo.get_uri_scheme() != "file" or fileinfo.is_directory():
return False, "Not a file"
return False, _("Not a file")
elif not fileinfo.can_write():
return False, "Not writeable"
return False, _("Not writeable")
return True, ""
def __create_treeview(self) -> Gtk.TreeView:
......@@ -120,7 +123,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
column_pixbuf = Gtk.TreeViewColumn("Icon", renderer_pixbuf, pixbuf=0)
treeview.append_column(column_pixbuf)
for idx, name in enumerate(['File', 'Reason']):
for idx, name in enumerate([_('File'), _('Reason')]):
renderer_text = Gtk.CellRendererText()
column_text = Gtk.TreeViewColumn(name, renderer_text, text=idx+1)
treeview.append_column(column_text)
......@@ -180,7 +183,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
return False
progressbar.pulse()
progressbar.set_text("Cleaning %s" % fname)
progressbar.set_text(_("Cleaning %s") % fname)
progressbar.show_all()
self.infobar_hbox.show_all()
self.infobar.show_all()
......@@ -202,7 +205,7 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
fpath = unquote(fileinfo.get_uri()[7:]) # `len('file://') = 7`
success, mtype = _remove_metadata(fpath)
if not success:
self.failed_items.append((fname, mtype, 'Unsupported/invalid'))
self.failed_items.append((fname, mtype, _('Unsupported/invalid')))
processing_queue.put(None) # signal that we processed all the files
return True
......@@ -236,8 +239,8 @@ class Mat2Extension(GObject.GObject, Nautilus.MenuProvider, Nautilus.LocationWid
item = Nautilus.MenuItem(
name="mat2::Remove_metadata",
label="Remove metadata",
tip="Remove metadata"
label=_("Remove metadata"),
tip=_("Remove metadata")
)
item.connect('activate', self.__cb_menu_activate, files)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment