extensions, po-plug-ins: demo extensions use the new i18n logic.

Since these are demos, for the sake of showing how the localization
works, let's localize the goat-exercises with a locally installed
catalog.
Note that actually use the gimp30-std-plug-ins catalog, simply I copy it
in the plug-in folder and rename it as org.gimp.extension.goat-exercises
domain.

As a consequence:

- The C plug-in does not need the INIT_I18N anymore, which was
  specifically for the centrally installed catalog and cannot be used by
  third-party plug-in developers (so it's not a good demo code).
- I now use GLib.dgettext() for Python instead of the gettext Python
  module, because the later won't "catch" the catalog declared in
  libgimp.
- The other Goat exercises are now localized correctly, unlike before.
- Just setting GETTEXT_PACKAGE is apparently enough for the Vala
  plug-in.
- Lua is untested. Hopefully the code will work.
This commit is contained in:
Jehan 2022-05-26 01:03:07 +02:00
parent 18c37f7084
commit 3e57f2f482
7 changed files with 33 additions and 31 deletions

View File

@ -142,8 +142,6 @@ goat_run (GimpProcedure *procedure,
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint x, y, width, height;
INIT_I18N();
if (n_drawables != 1)
{
GError *error = NULL;

View File

@ -44,6 +44,8 @@ ARGV.unshift(System.programInvocationName);
let url = "https://gitlab.gnome.org/GNOME/gimp/blob/master/extensions/goat-exercises/goat-exercise-gjs.js";
function _(message) { return GLib.dgettext(null, message); }
var Goat = GObject.registerClass({
GTypeName: 'Goat',
}, class Goat extends Gimp.PlugIn {
@ -58,12 +60,12 @@ var Goat = GObject.registerClass({
procedure.set_image_types("*");
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE);
procedure.set_menu_label("Exercise a JavaScript goat");
procedure.set_menu_label(_("Exercise a JavaScript goat"));
procedure.set_icon_name(GimpUi.ICON_GEGL);
procedure.add_menu_path ('<Image>/Filters/Development/Goat exercises/');
procedure.set_documentation("Exercise a goat in the JavaScript language (GJS)",
"Takes a goat for a walk in Javascript with the GJS interpreter",
procedure.set_documentation(_("Exercise a goat in the JavaScript language (GJS)"),
_("Takes a goat for a walk in Javascript with the GJS interpreter"),
name);
procedure.set_attribution("Jehan", "Jehan", "2019");
@ -85,13 +87,13 @@ var Goat = GObject.registerClass({
GimpUi.init("goat-exercise-gjs");
/* TODO: help function and ID. */
let dialog = new GimpUi.Dialog({
title: "Exercise a goat (JavaScript)",
title: _("Exercise a goat (JavaScript)"),
role: "goat-exercise-JavaScript",
use_header_bar: true,
});
dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL);
dialog.add_button("_Source", Gtk.ResponseType.APPLY);
dialog.add_button("_OK", Gtk.ResponseType.OK);
dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL);
dialog.add_button(_("_Source"), Gtk.ResponseType.APPLY);
dialog.add_button(_("_OK"), Gtk.ResponseType.OK);
let geometry = new Gdk.Geometry();
geometry.min_aspect = 0.5;

View File

@ -33,6 +33,14 @@ local Gdk = lgi.Gdk
local Goat = lgi.package 'Goat'
local Goat = lgi.Goat
function N_(message)
return message;
end
function _(message)
return GLib.dgettext(nil, message);
end
function run(procedure, run_mode, image, drawables, args, run_data)
-- procedure:new_return_values() crashes LGI so we construct the
-- GimpValueArray manually.
@ -56,13 +64,13 @@ function run(procedure, run_mode, image, drawables, args, run_data)
if run_mode == "INTERACTIVE" then
GimpUi.init("goat-exercise-lua");
local dialog = GimpUi.Dialog {
title = "Exercise a goat (Lua)",
title = N_("Exercise a goat (Lua)"),
role = "goat-exercise-Lua",
use_header_bar = 1
}
dialog:add_button("_Cancel", Gtk.ResponseType.CANCEL);
dialog:add_button("_Source", Gtk.ResponseType.APPLY);
dialog:add_button("_OK", Gtk.ResponseType.OK);
dialog:add_button(_("_Cancel"), Gtk.ResponseType.CANCEL);
dialog:add_button(_("_Source"), Gtk.ResponseType.APPLY);
dialog:add_button(_("_OK"), Gtk.ResponseType.OK);
local geometry = Gdk.Geometry()
geometry.min_aspect = 0.5;

View File

@ -24,28 +24,15 @@ from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
import gettext
import os
import sys
# Set-up localization for your plug-in with your own text domain.
# This is complementary to the gimp_plug_in_set_translation_domain()
# which is only useful for the menu entries inside GIMP interface,
# whereas the below calls are used for localization within the plug-in.
textdomain = 'gimp30-std-plug-ins'
gettext.bindtextdomain(textdomain, Gimp.locale_directory())
gettext.textdomain(textdomain)
_ = gettext.gettext
def N_(message): return message
def _(message): return GLib.dgettext(None, message)
class Goat (Gimp.PlugIn):
## GimpPlugIn virtual methods ##
def do_query_procedures(self):
# Localization for the menu entries. It has to be called in the
# query function only.
self.set_translation_domain(textdomain,
Gio.file_new_for_path(Gimp.locale_directory()))
return [ "plug-in-goat-exercise-python" ]
def do_create_procedure(self, name):

View File

@ -42,9 +42,9 @@ public class Goat : Gimp.PlugIn {
var procedure = new Gimp.ImageProcedure(this, name, Gimp.PDBProcType.PLUGIN, this.run);
procedure.set_image_types("RGB*, INDEXED*, GRAY*");
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE);
procedure.set_menu_label("Exercise a Vala goat");
procedure.set_documentation("Exercise a goat in the Vala language",
"Takes a goat for a walk in Vala",
procedure.set_menu_label(N_("Exercise a Vala goat"));
procedure.set_documentation(N_("Exercise a goat in the Vala language"),
N_("Takes a goat for a walk in Vala"),
PLUG_IN_PROC);
procedure.add_menu_path("<Image>/Filters/Development/Goat exercises/");
procedure.set_attribution("Niels De Graef", "Niels De Graef", "2020");

View File

@ -50,7 +50,7 @@ if have_vala and have_gobject_introspection
libgimp_vapi, libgimpui_vapi, gtk3, gegl, math,
],
c_args: [
'-DGETTEXT_PACKAGE="@0@"'.format(gettext_package),
'-DGETTEXT_PACKAGE="@0@"'.format('org.gimp.extension.goat-exercises'),
],
install: true,
install_dir: gimpplugindir / 'extensions' / extension_name,

View File

@ -1,2 +1,9 @@
po_plug_ins_dir = meson.current_source_dir()
i18n.gettext(gettext_package + '-std-plug-ins', preset: 'glib')
# Special-casing, we just reuse the same locale dictionnary for our demo
# extension. We could have separated the strings but just for the sake
# of demo on code-side, it's simpler to do it this way.
extension_i18n = 'org.gimp.extension.goat-exercises'
i18n.gettext(extension_i18n, preset: 'glib',
install_dir: gimpplugindir / 'extensions' / extension_i18n / 'locale')