From 5a23a36c2d9cf68bd08cf150abfae961e0ee38f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Mon, 5 Jun 2017 22:39:23 +0200 Subject: [PATCH 3/3] Created a new example program for translating plugin files. * gettext-tools/examples/hello-c-plugin: Plugin example using GTK and libpeas. * gettext-tools/examples/Makefile.am: Added hello-c-plugin files. * gettext-tools/examples/README: Listed hello-c-plugin and dependencies. * gettext-tools/examples/po/Makefile.am: Added hello-c-plugin translatable files. --- gettext-tools/examples/Makefile.am | 21 +++ gettext-tools/examples/README | 1 + gettext-tools/examples/hello-c-plugin/INSTALL | 12 ++ gettext-tools/examples/hello-c-plugin/Makefile.am | 62 +++++++++ gettext-tools/examples/hello-c-plugin/autoclean.sh | 73 ++++++++++ gettext-tools/examples/hello-c-plugin/autogen.sh | 31 +++++ gettext-tools/examples/hello-c-plugin/configure.ac | 81 +++++++++++ gettext-tools/examples/hello-c-plugin/hello.c | 150 +++++++++++++++++++++ .../examples/hello-c-plugin/hello.desktop.in.in | 6 + .../examples/hello-c-plugin/hello.gresource.xml | 6 + .../examples/hello-c-plugin/hello.gschema.xml | 11 ++ gettext-tools/examples/hello-c-plugin/hello.ui | 18 +++ .../examples/hello-c-plugin/m4/Makefile.am | 5 + .../examples/hello-c-plugin/plugins/Makefile.am | 1 + .../hello-c-plugin/plugins/hello/Makefile.am | 29 ++++ .../hello-c-plugin/plugins/hello/hello-plugin.c | 129 ++++++++++++++++++ .../hello-c-plugin/plugins/hello/hello-plugin.h | 17 +++ .../hello-c-plugin/plugins/hello/hello.plugin.in | 8 ++ gettext-tools/examples/hello-c-plugin/po/LINGUAS | 5 + gettext-tools/examples/hello-c-plugin/po/Makevars | 67 +++++++++ .../examples/hello-c-plugin/po/POTFILES.in | 9 ++ gettext-tools/examples/po/Makefile.am | 14 ++ 22 files changed, 756 insertions(+) create mode 100644 gettext-tools/examples/hello-c-plugin/INSTALL create mode 100644 gettext-tools/examples/hello-c-plugin/Makefile.am create mode 100755 gettext-tools/examples/hello-c-plugin/autoclean.sh create mode 100755 gettext-tools/examples/hello-c-plugin/autogen.sh create mode 100644 gettext-tools/examples/hello-c-plugin/configure.ac create mode 100644 gettext-tools/examples/hello-c-plugin/hello.c create mode 100644 gettext-tools/examples/hello-c-plugin/hello.desktop.in.in create mode 100644 gettext-tools/examples/hello-c-plugin/hello.gresource.xml create mode 100644 gettext-tools/examples/hello-c-plugin/hello.gschema.xml create mode 100644 gettext-tools/examples/hello-c-plugin/hello.ui create mode 100644 gettext-tools/examples/hello-c-plugin/m4/Makefile.am create mode 100644 gettext-tools/examples/hello-c-plugin/plugins/Makefile.am create mode 100644 gettext-tools/examples/hello-c-plugin/plugins/hello/Makefile.am create mode 100644 gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.c create mode 100644 gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.h create mode 100644 gettext-tools/examples/hello-c-plugin/plugins/hello/hello.plugin.in create mode 100644 gettext-tools/examples/hello-c-plugin/po/LINGUAS create mode 100644 gettext-tools/examples/hello-c-plugin/po/Makevars create mode 100644 gettext-tools/examples/hello-c-plugin/po/POTFILES.in diff --git a/gettext-tools/examples/Makefile.am b/gettext-tools/examples/Makefile.am index a8bcd54be..44ea8f91f 100644 --- a/gettext-tools/examples/Makefile.am +++ b/gettext-tools/examples/Makefile.am @@ -65,6 +65,26 @@ EXAMPLESFILES = \ hello-c-gnome3/po/Makevars \ hello-c-gnome3/po/POTFILES.in \ \ + hello-c-plugin/INSTALL \ + hello-c-plugin/autogen.sh \ + hello-c-plugin/autoclean.sh \ + hello-c-plugin/hello.c \ + hello-c-plugin/hello.desktop.in.in \ + hello-c-plugin/hello.gschema.xml \ + hello-c-plugin/hello.gresource.xml \ + hello-c-plugin/hello.ui \ + hello-c-plugin/Makefile.am \ + hello-c-plugin/configure.ac \ + hello-c-plugin/m4/Makefile.am \ + hello-c-plugin/po/Makevars \ + hello-c-plugin/po/LINGUAS \ + hello-c-plugin/po/POTFILES.in \ + hello-c-plugin/plugins/Makefile.am \ + hello-c-plugin/plugins/hello/hello-plugin.c \ + hello-c-plugin/plugins/hello/hello-plugin.h \ + hello-c-plugin/plugins/hello/hello.plugin.in \ + hello-c-plugin/plugins/hello/Makefile.am \ + \ hello-c++/INSTALL \ hello-c++/autogen.sh \ hello-c++/autoclean.sh \ @@ -376,6 +396,7 @@ EXAMPLESDIRS = \ hello-c \ hello-c-gnome \ hello-c-gnome3 \ + hello-c-plugin \ hello-c++ \ hello-c++-qt \ hello-c++-kde \ diff --git a/gettext-tools/examples/README b/gettext-tools/examples/README index 4eff716d1..061033f6a 100644 --- a/gettext-tools/examples/README +++ b/gettext-tools/examples/README @@ -8,6 +8,7 @@ environment. hello-c C hello-c-gnome C GNOME (obsolete) hello-c-gnome3 C GNOME 3.10 or later + hello-c-plugin C GNOME 3.10 and libpeas 1.0 hello-c++ C++ hello-c++-qt C++ Qt hello-c++-kde C++ KDE diff --git a/gettext-tools/examples/hello-c-plugin/INSTALL b/gettext-tools/examples/hello-c-plugin/INSTALL new file mode 100644 index 000000000..3b9f22fe0 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/INSTALL @@ -0,0 +1,12 @@ +This example relies on: + - the GTK libraries (libgtk, libgdk), version 3.10 or later + - the glib libraries (libglib) + +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/gettext-tools/examples/hello-c-plugin/Makefile.am b/gettext-tools/examples/hello-c-plugin/Makefile.am new file mode 100644 index 000000000..c93e24ed5 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/Makefile.am @@ -0,0 +1,62 @@ +# Example for use of GNU gettext. +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies +ACLOCAL_AMFLAGS = -I m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = plugins m4 po + +# The list of programs that are built. +bin_PROGRAMS = hello + +# The source files of the 'hello' program. +hello_SOURCES = hello.c resources.c + +# Define a C macro LOCALEDIR indicating where catalogs will be installed. +DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ + +# Make sure the gnome.h include file is found. +AM_CPPFLAGS = $(GTK_CFLAGS) $(PEAS_CFLAGS) $(PEAS_GTK_CFLAGS) + +# Link time dependencies. +LDADD = $(GTK_LIBS) $(PEAS_LIBS) $(PEAS_GTK_LIBS) @LIBINTL@ + +BUILT_SOURCES = gschemas.compiled resources.c + +# Compile GSettings schema. +gschemas.compiled: hello.gschema.xml + $(AM_V_GEN) $(GLIB_COMPILE_SCHEMAS) . + +# Compile assets into a C source and link it with the application. +resources.c: hello.gresource.xml hello.ui + $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \ + --sourcedir=$(srcdir) --generate-source + +desktopdir = $(datadir)/applications +desktop_DATA = hello.desktop + +# Merge translations back into a Desktop Entry file. + +# Note that the resulting file should be included in EXTRA_DIST and +# processed earlier than the variable substitution below. Otherwise, +# the 'msgfmt' command will be required at compile-time. +hello.desktop.in: hello.desktop.in.in + $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@ + +# Substitute variables in a Desktop Entry file. +hello.desktop: hello.desktop.in + $(AM_V_GEN) sed -e 's|@address@hidden|$(bindir)|g' $< > $@ + +CLEANFILES = $(BUILT_SOURCES) hello.desktop $(desktop_DATA) + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh hello.ui \ + hello.desktop.in.in hello.desktop.in \ + hello.gschema.xml \ + hello.gresource.xml + +MAINTAINERCLEANFILES = hello.desktop.in diff --git a/gettext-tools/examples/hello-c-plugin/autoclean.sh b/gettext-tools/examples/hello-c-plugin/autoclean.sh new file mode 100755 index 000000000..8ea382e1b --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/autoclean.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Example for use of GNU gettext. +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Brought in by autopoint. +rm -f ABOUT-NLS +rm -f config.rpath +rm -f m4/codeset.m4 +rm -f m4/gettext.m4 +rm -f m4/glibc2.m4 +rm -f m4/glibc21.m4 +rm -f m4/iconv.m4 +rm -f m4/intdiv0.m4 +rm -f m4/intl.m4 +rm -f m4/intldir.m4 +rm -f m4/intlmacosx.m4 +rm -f m4/intmax.m4 +rm -f m4/inttypes-pri.m4 +rm -f m4/inttypes_h.m4 +rm -f m4/lcmessage.m4 +rm -f m4/lib-ld.m4 +rm -f m4/lib-link.m4 +rm -f m4/lib-prefix.m4 +rm -f m4/lock.m4 +rm -f m4/longlong.m4 +rm -f m4/nls.m4 +rm -f m4/po.m4 +rm -f m4/printf-posix.m4 +rm -f m4/progtest.m4 +rm -f m4/size_max.m4 +rm -f m4/stdint_h.m4 +rm -f m4/uintmax_t.m4 +rm -f m4/visibility.m4 +rm -f m4/wchar_t.m4 +rm -f m4/wint_t.m4 +rm -f m4/xsize.m4 +rm -f po/Makefile.in.in +rm -f po/remove-potcdate.sin + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by libtoolize +rm -f compile +rm -f depcomp +rm -f missing +unlink config.guess +unlink config.sub +unlink install-sh +unlink ltmain.sh +unlink m4/libtool.m4 +unlink m4/lt~obsolete.m4 +unlink m4/ltoptions.m4 +unlink m4/ltsugar.m4 +unlink m4/ltversion.m4 + +# Generated by autoconf. +rm -f configure + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f install-sh +rm -f missing +rm -f config.guess +rm -f config.sub +rm -f po/*.pot +rm -f po/stamp-po +rm -f po/*.gmo diff --git a/gettext-tools/examples/hello-c-plugin/autogen.sh b/gettext-tools/examples/hello-c-plugin/autogen.sh new file mode 100755 index 000000000..862c80a84 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/autogen.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Example for use of GNU gettext. +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +autopoint -f # was: gettextize -f -c +rm po/Makevars.template +rm po/Rules-quot +rm po/boldquot.sed +rm po/address@hidden +rm po/address@hidden +rm po/insert-header.sin +rm po/quot.sed + +aclocal -I m4 + +libtoolize --verbose --force --install || exit $? + +autoconf + +automake -a -c + +cd po +for f in *.po; do + if test -r "$f"; then + lang=`echo $f | sed -e 's,\.po$,,'` + msgfmt -c -o $lang.gmo $lang.po + fi +done +cd .. diff --git a/gettext-tools/examples/hello-c-plugin/configure.ac b/gettext-tools/examples/hello-c-plugin/configure.ac new file mode 100644 index 000000000..33d6cf344 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/configure.ac @@ -0,0 +1,81 @@ +dnl Example for use of GNU gettext. +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT +AC_CONFIG_SRCDIR(hello.c) +AM_INIT_AUTOMAKE(hello-c-plugin, 0) + +LT_INIT + +AC_PROG_CC +AM_GNU_GETTEXT([external]) +AM_GNU_GETTEXT_VERSION(0.19) + +dnl Check GNOME specific stuff. +dnl +dnl If you have full GNOME development environment installed on your +dnl system, you should be able to use the following macros: +dnl +dnl AM_PATH_GLIB_2_0 +dnl PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.10], , +dnl [AC_MSG_ERROR([can't find gtk+-3.0])]) +dnl +dnl Here, in gettext-tools/examples, we do the checks manually for +dnl simplicity. + +AC_PATH_PROG(GLIB_COMPILE_RESOURCES, [glib-compile-resources]) +AS_IF([test -z "$GLIB_COMPILE_RESOURCES"], [ + AC_MSG_ERROR([can't find glib-compile-resources]) +]) + +AC_PATH_PROG(GLIB_COMPILE_SCHEMAS, [glib-compile-schemas]) +AS_IF([test -z "$GLIB_COMPILE_SCHEMAS"], [ + AC_MSG_ERROR([can't find glib-compile-schemas]) +]) + +AC_PATH_PROG([PKG_CONFIG], [pkg-config]) +AS_IF([test -z "$PKG_CONFIG"], [ + AC_MSG_ERROR([can't find pkg-config]) +]) + +GTK="gtk+-3.0 >= 3.10" +AS_IF(["$PKG_CONFIG" --exists "$GTK"], , [ + AC_MSG_ERROR([can't find $GTK]) +]) + +GTK_CFLAGS=`"$PKG_CONFIG" --cflags "$GTK"` +AC_SUBST(GTK_CFLAGS) + +GTK_LIBS=`"$PKG_CONFIG" --libs "$GTK"` +AC_SUBST(GTK_LIBS) + +PEAS="libpeas-1.0" +AS_IF(["$PKG_CONFIG" --exists "$PEAS"], , [ + AC_MSG_ERROR([can't find $PEAS]) +]) + +PEAS_CFLAGS=`"$PKG_CONFIG" --cflags "$PEAS"` +AC_SUBST(PEAS_CFLAGS) + +PEAS_LIBS=`"$PKG_CONFIG" --libs "$PEAS"` +AC_SUBST(PEAS_LIBS) + +PEAS_GTK="libpeas-gtk-1.0" +AS_IF(["$PKG_CONFIG" --exists "$PEAS_GTK"], , [ + AC_MSG_ERROR([can't find $PEAS_GTK]) +]) + +PEAS_GTK_CFLAGS=`"$PKG_CONFIG" --cflags "$PEAS_GTK"` +AC_SUBST(PEAS_GTK_CFLAGS) + +PEAS_GTK_LIBS=`"$PKG_CONFIG" --libs "$PEAS_GTK"` +AC_SUBST(PEAS_GTK_LIBS) + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([plugins/Makefile]) +AC_CONFIG_FILES([plugins/hello/Makefile]) +AC_CONFIG_FILES([m4/Makefile]) +AC_CONFIG_FILES([po/Makefile.in]) +AC_OUTPUT diff --git a/gettext-tools/examples/hello-c-plugin/hello.c b/gettext-tools/examples/hello-c-plugin/hello.c new file mode 100644 index 000000000..64986d234 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/hello.c @@ -0,0 +1,150 @@ +/* Example for use of GNU gettext. + This file is in the public domain. + + Source code of the C program. */ + + +/* Get GTK declarations. */ +#include +#include + +/* Get libpeas GTK plugin manager declarations */ +#include + +#define UI_PATH "/org/gnu/gettext/examples/hello/hello.ui" +#define APPLICATION_ID "org.gnu.gettext.examples.hello" +#define GSETTINGS_SCHEMA "org.gnu.gettext.examples.hello" + +/* Forward declaration of GObject types. */ + +#define HELLO_TYPE_APPLICATION_WINDOW (hello_application_window_get_type ()) +#define HELLO_APPLICATION_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + HELLO_TYPE_APPLICATION_WINDOW, \ + HelloApplicationWindow)) + +typedef struct _HelloApplicationWindow HelloApplicationWindow; +typedef struct _HelloApplicationWindowClass HelloApplicationWindowClass; + +#define HELLO_TYPE_APPLICATION (hello_application_get_type ()) +#define HELLO_APPLICATION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + HELLO_TYPE_APPLICATION, \ + HelloApplication)) + +typedef struct _HelloApplication HelloApplication; +typedef struct _HelloApplicationClass HelloApplicationClass; + +/* Custom application window implementation. */ + +struct _HelloApplicationWindow +{ + GtkApplicationWindow parent; + GtkWidget *plugin_manager; +}; + +struct _HelloApplicationWindowClass +{ + GtkApplicationWindowClass parent_class; +}; + +G_DEFINE_TYPE (HelloApplicationWindow, hello_application_window, + GTK_TYPE_APPLICATION_WINDOW); + +static void +hello_application_window_init (HelloApplicationWindow *window) +{ + gtk_widget_init_template (GTK_WIDGET (window)); +} + +static void +hello_application_window_class_init (HelloApplicationWindowClass *klass) +{ + g_type_ensure (PEAS_GTK_TYPE_PLUGIN_MANAGER); + + gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), + UI_PATH); + gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), + HelloApplicationWindow, plugin_manager); +} + +static HelloApplicationWindow * +hello_application_window_new (HelloApplication *application) +{ + return g_object_new (HELLO_TYPE_APPLICATION_WINDOW, + "application", application, + NULL); +} + +/* Custom application implementation. */ + +struct _HelloApplication +{ + GtkApplication parent; +}; + +struct _HelloApplicationClass +{ + GtkApplicationClass parent_class; +}; + +G_DEFINE_TYPE (HelloApplication, hello_application, GTK_TYPE_APPLICATION); + +static void +hello_application_init (HelloApplication *application) +{ +} + +static void +hello_application_activate (GApplication *application) +{ + HelloApplicationWindow *window; + + window = hello_application_window_new (HELLO_APPLICATION (application)); + + gtk_widget_show_all (GTK_WIDGET (window)); +} + +static void +hello_application_class_init (HelloApplicationClass *klass) +{ + G_APPLICATION_CLASS (klass)->activate = hello_application_activate; +} + +static HelloApplication * +hello_application_new (void) +{ + return g_object_new (HELLO_TYPE_APPLICATION, + "application-id", APPLICATION_ID, + NULL); +} + +int +main (int argc, char *argv[]) +{ + GApplication *application; + PeasEngine *engine; + gchar *plugin_dir; + int status; + + /* Load the GSettings schema from the current directory. */ + g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE); + + /* Initializations. */ + textdomain ("hello-c-plugin"); + bindtextdomain ("hello-c-plugin", LOCALEDIR); + + engine = peas_engine_get_default (); + peas_engine_add_search_path (engine, "plugins", "plugins"); + + /* Create application. */ + application = G_APPLICATION (hello_application_new ()); + + /* Start the application. */ + status = g_application_run (application, argc, argv); + g_object_unref (application); + + g_object_unref (engine); + + return status; +} diff --git a/gettext-tools/examples/hello-c-plugin/hello.desktop.in.in b/gettext-tools/examples/hello-c-plugin/hello.desktop.in.in new file mode 100644 index 000000000..a31bf9337 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/hello.desktop.in.in @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Application +Name=Hello +Comment=Hello, world! +StartupNotify=true address@hidden@/hello diff --git a/gettext-tools/examples/hello-c-plugin/hello.gresource.xml b/gettext-tools/examples/hello-c-plugin/hello.gresource.xml new file mode 100644 index 000000000..4d2c27810 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/hello.gresource.xml @@ -0,0 +1,6 @@ + + + + hello.ui + + diff --git a/gettext-tools/examples/hello-c-plugin/hello.gschema.xml b/gettext-tools/examples/hello-c-plugin/hello.gschema.xml new file mode 100644 index 000000000..d586b5a74 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/hello.gschema.xml @@ -0,0 +1,11 @@ + + + + + true + Use XML markup + Whether to use XML markup in the text. + + + diff --git a/gettext-tools/examples/hello-c-plugin/hello.ui b/gettext-tools/examples/hello-c-plugin/hello.ui new file mode 100644 index 000000000..7fb7c7e2b --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/hello.ui @@ -0,0 +1,18 @@ + + + + + + diff --git a/gettext-tools/examples/hello-c-plugin/m4/Makefile.am b/gettext-tools/examples/hello-c-plugin/m4/Makefile.am new file mode 100644 index 000000000..000cd06f0 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/m4/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = \ + codeset.m4 gettext.m4 glibc2.m4 glibc21.m4 iconv.m4 intdiv0.m4 \ + inttypes_h.m4 inttypes-pri.m4 lcmessage.m4 lib-ld.m4 lib-link.m4 \ + lib-prefix.m4 lock.m4 nls.m4 po.m4 progtest.m4 stdint_h.m4 \ + uintmax_t.m4 visibility.m4 diff --git a/gettext-tools/examples/hello-c-plugin/plugins/Makefile.am b/gettext-tools/examples/hello-c-plugin/plugins/Makefile.am new file mode 100644 index 000000000..33042f073 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = hello diff --git a/gettext-tools/examples/hello-c-plugin/plugins/hello/Makefile.am b/gettext-tools/examples/hello-c-plugin/plugins/hello/Makefile.am new file mode 100644 index 000000000..08248c4fa --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/plugins/hello/Makefile.am @@ -0,0 +1,29 @@ +plugindir = $(abs_top_builddir)/plugins/hello + +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + $(PEAS_CFLAGS) \ + $(PEAS_GTK_CFLAGS) + +plugin_LTLIBRARIES = libhello.la + +libhello_la_SOURCES = \ + hello-plugin.h \ + hello-plugin.c + +libhello_la_LDFLAGS = \ + -module \ + -avoid-version \ + -no-undefined + +libhello_la_LIBADD = \ + $(PEAS_LIBS) \ + $(PEAS_GTK_LIBS) + +hello.plugin: hello.plugin.in + $(AM_V_GEN) $(MSGFMT) --plugin --template $< -d $(top_srcdir)/po -o $@ + +plugin_DATA = hello.plugin + +CLEANFILES = $(plugin_DATA) +EXTRA_DIST = hello.plugin.in diff --git a/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.c b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.c new file mode 100644 index 000000000..123a575ef --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.c @@ -0,0 +1,129 @@ +#include +#include +#include + +#include "hello-plugin.h" + +struct _HelloPlugin +{ + PeasExtensionBase parent; + + GtkWidget *window; +}; + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (HelloPlugin, + hello_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +enum { + PROP_0, + PROP_OBJECT +}; + +static void +hello_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + HelloPlugin *plugin = HELLO_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +hello_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + HelloPlugin *plugin = HELLO_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +hello_plugin_init (HelloPlugin *plugin) +{ + g_debug ("%s", G_STRFUNC); +} + +static void +hello_plugin_finalize (GObject *object) +{ + HelloPlugin *plugin = HELLO_PLUGIN (object); + + g_debug ("%s", G_STRFUNC); + + g_object_unref (plugin->window); + + G_OBJECT_CLASS (hello_plugin_parent_class)->finalize (object); +} + +static void +hello_plugin_activate (PeasActivatable *activatable) +{ + g_debug ("%s", G_STRFUNC); +} + +static void +hello_plugin_deactivate (PeasActivatable *activatable) +{ + g_debug ("%s", G_STRFUNC); +} + +static void +hello_plugin_class_init (HelloPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = hello_plugin_set_property; + object_class->get_property = hello_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); +} + +static void +hello_plugin_class_finalize (HelloPluginClass *klass) +{ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = hello_plugin_activate; + iface->deactivate = hello_plugin_deactivate; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + hello_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + HELLO_TYPE_PLUGIN); +} diff --git a/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.h b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.h new file mode 100644 index 000000000..d709b29fe --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello-plugin.h @@ -0,0 +1,17 @@ +#ifndef HELLO_PLUGIN_H +#define HELLO_PLUGIN_H + +#include +#include + +G_BEGIN_DECLS + +#define HELLO_TYPE_PLUGIN (hello_plugin_get_type()) + +G_DECLARE_FINAL_TYPE (HelloPlugin, hello_plugin, HELLO, PLUGIN, PeasExtensionBase) + +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_END_DECLS + +#endif /* HELLO_PLUGIN_H */ diff --git a/gettext-tools/examples/hello-c-plugin/plugins/hello/hello.plugin.in b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello.plugin.in new file mode 100644 index 000000000..449f2a1c8 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/plugins/hello/hello.plugin.in @@ -0,0 +1,8 @@ +[Plugin] +Module=hello +Name=Hello Plugin +Description=Hello Plugin for Hello application +Authors=Plugin author +Copyright=Copyright (C) Plugin author +Website=https://www.gnu.org/software/gettext/ +Help=https://www.gnu.org/software/gettext/ diff --git a/gettext-tools/examples/hello-c-plugin/po/LINGUAS b/gettext-tools/examples/hello-c-plugin/po/LINGUAS new file mode 100644 index 000000000..339c7f92f --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/po/LINGUAS @@ -0,0 +1,5 @@ +# Example for use of GNU gettext. +# This file is in the public domain. +# +# Set of available languages. +af ast bg ca cs da de el eo es fi fr ga gl hr hu id it ja ky lv ms mt nb nl pl pt pt_BR ro ru sk sl sr sv tr uk vi zh_CN zh_HK zh_TW diff --git a/gettext-tools/examples/hello-c-plugin/po/Makevars b/gettext-tools/examples/hello-c-plugin/po/Makevars new file mode 100644 index 000000000..7b158ff9b --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/po/Makevars @@ -0,0 +1,67 @@ +# Makefile variables for PO directory in any package using GNU gettext. + +# Usually the message domain is the same as the package name. +DOMAIN = $(PACKAGE) + +# These two variables depend on the location of this directory. +subdir = po +top_builddir = .. + +# These options get passed to xgettext. +XGETTEXT_OPTIONS = \ + --keyword=_ --flag=_:1:pass-c-format \ + --keyword=N_ --flag=N_:1:pass-c-format \ + --flag=g_log:3:c-format --flag=g_logv:3:c-format \ + --flag=g_error:1:c-format --flag=g_message:1:c-format \ + --flag=g_critical:1:c-format --flag=g_warning:1:c-format \ + --flag=g_print:1:c-format \ + --flag=g_printerr:1:c-format \ + --flag=g_strdup_printf:1:c-format --flag=g_strdup_vprintf:1:c-format \ + --flag=g_printf_string_upper_bound:1:c-format \ + --flag=g_snprintf:3:c-format --flag=g_vsnprintf:3:c-format \ + --flag=g_string_sprintf:2:c-format \ + --flag=g_string_sprintfa:2:c-format \ + --flag=g_scanner_error:2:c-format \ + --flag=g_scanner_warn:2:c-format + +# This is the copyright holder that gets inserted into the header of the +# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding +# package. (Note that the msgstr strings, extracted from the package's +# sources, belong to the copyright holder of the package.) Translators are +# expected to transfer the copyright for their translations to this person +# or entity, or to disclaim their copyright. The empty string stands for +# the public domain; in this case the translators are expected to disclaim +# their copyright. +COPYRIGHT_HOLDER = Yoyodyne, Inc. + +# This is the email address or URL to which the translators shall report +# bugs in the untranslated strings: +# - Strings which are not entire sentences, see the maintainer guidelines +# in the GNU gettext documentation, section 'Preparing Strings'. +# - Strings which use unclear terms or require additional context to be +# understood. +# - Strings which make invalid assumptions about notation of date, time or +# money. +# - Pluralisation problems. +# - Incorrect English spelling. +# - Incorrect formatting. +# It can be your email address, or a mailing list address where translators +# can write to without being subscribed, or the URL of a web page through +# which the translators can contact you. +MSGID_BUGS_ADDRESS = address@hidden + +# This is the list of locale categories, beyond LC_MESSAGES, for which the +# message catalogs shall be used. It is usually empty. +EXTRA_LOCALE_CATEGORIES = + +# This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt' +# context. Possible values are "yes" and "no". Set this to yes if the +# package uses functions taking also a message context, like pgettext(), or +# if in $(XGETTEXT_OPTIONS) you define keywords with a context argument. +USE_MSGCTXT = no + +# These options get passed to msgmerge. +# Useful options are in particular: +# --previous to keep previous msgids of translated messages, +# --quiet to reduce the verbosity. +MSGMERGE_OPTIONS = --quiet diff --git a/gettext-tools/examples/hello-c-plugin/po/POTFILES.in b/gettext-tools/examples/hello-c-plugin/po/POTFILES.in new file mode 100644 index 000000000..9fa11da95 --- /dev/null +++ b/gettext-tools/examples/hello-c-plugin/po/POTFILES.in @@ -0,0 +1,9 @@ +# Example for use of GNU gettext. +# This file is in the public domain. +# +# List of files which contain translatable strings. +hello.c +hello.desktop.in.in +hello.ui +hello.gschema.xml +plugins/hello/hello.plugin.in diff --git a/gettext-tools/examples/po/Makefile.am b/gettext-tools/examples/po/Makefile.am index d4f1ad651..49b99016f 100644 --- a/gettext-tools/examples/po/Makefile.am +++ b/gettext-tools/examples/po/Makefile.am @@ -27,6 +27,12 @@ POTFILES = \ hello-c-gnome3/hello.desktop.in.in \ hello-c-gnome3/hello.gschema.xml \ hello-c-gnome3/hello.ui \ + hello-c-plugin/hello.c \ + hello-c-plugin/hello.desktop.in.in \ + hello-c-plugin/hello.gschema.xml \ + hello-c-plugin/hello.ui \ + hello-c-plugin/plugins/hello-plugin.c \ + hello-c-plugin/plugins/hello.plugin.in \ hello-c++/hello.cc \ hello-c++-qt/hello.cc \ hello-c++-kde/hello.cc \ @@ -67,6 +73,7 @@ SMALLPOTS = \ hello-c.pot \ hello-c-gnome.pot \ hello-c-gnome3.pot \ + hello-c-plugin.pot \ hello-c++.pot \ hello-c++-qt.pot \ hello-c++-kde.pot \ @@ -226,6 +233,9 @@ hello-c-gnome.pot : $(POTFILES_DEPS) hello-c-gnome3.pot : $(POTFILES_DEPS) $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c-gnome3 +hello-c-plugin.pot : $(POTFILES_DEPS) + $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c-plugin + hello-c++.pot : $(POTFILES_DEPS) $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c++ @@ -386,6 +396,7 @@ SMALLPOFILES_FOR_lang = \ ../hello-c/po/$$lang.po \ ../hello-c-gnome/po/$$lang.po \ ../hello-c-gnome3/po/$$lang.po \ + ../hello-c-plugin/po/$$lang.po \ ../hello-c++/po/$$lang.po \ ../hello-c++-qt/po/$$lang.po \ ../hello-c++-kde/po/$$lang.po \ @@ -423,6 +434,9 @@ SMALLPOFILES_FOR_lang = \ ../hello-c-gnome3/po/$(LL).po: hello-c-gnome3.pot $(LL).po $(SHELL) mmsmallpo.sh hello-c-gnome3 $(LL) +../hello-c-plugin/po/$(LL).po: hello-c-plugin.pot $(LL).po + $(SHELL) mmsmallpo.sh hello-c-plugin $(LL) + ../hello-c++/po/$(LL).po: hello-c++.pot $(LL).po $(SHELL) mmsmallpo.sh hello-c++ $(LL) -- 2.11.0