im.pidgin.cpw.rekkanoryo.examples: 39d0b56cb9ecfa6270072e6e77942626ce3ad420

rekkanoryo at pidgin.im rekkanoryo at pidgin.im
Mon Nov 26 05:11:41 EST 2007


-----------------------------------------------------------------
Revision: 39d0b56cb9ecfa6270072e6e77942626ce3ad420
Ancestor: 497031bbd8807c671e88cb285435e7eacb9b042d
Author: rekkanoryo at pidgin.im
Date: 2007-11-26T09:58:34
Branch: im.pidgin.cpw.rekkanoryo.examples

Modified files:
        libpurple/plugins/Makefile.am
        libpurple/plugins/translation_example.c

ChangeLog: 

Finish the translation example plugin.  I still get three compiler warnings:

translation_example.c: In function 'init_plugin':
translation_example.c:158: warning: assignment discards qualifiers from pointer target type
translation_example.c:159: warning: assignment discards qualifiers from pointer target type
translation_example.c:160: warning: assignment discards qualifiers from pointer target type

I have looked at this and don't see the problem.  There is nothing particularly
extravagant here.  I did try a couple blind stabs in the dark and found one that
worked, but it shouldn't be necessary because the cast is already in the macro.

-------------- next part --------------
============================================================
--- libpurple/plugins/Makefile.am	ad73a2aa4745a819758a5c14e2b40b537bd1c896
+++ libpurple/plugins/Makefile.am	a6f66ec2f50cba5f9cf762a15b1358c4de42ce06
@@ -71,7 +71,7 @@ noinst_LTLIBRARIES = \
 	request_example.la \
 	signals_test.la \
 	simple.la \
-	tranlsation_example.la
+	translation_example.la
 
 autoaccept_la_SOURCES         = autoaccept.c
 buddynote_la_SOURCES          = buddynote.c
@@ -91,7 +91,7 @@ statenotify_la_SOURCES        = statenot
 signals_test_la_SOURCES       = signals-test.c
 simple_la_SOURCES             = simple.c
 statenotify_la_SOURCES        = statenotify.c
-translation_example_la_SOURCES = request_example.c
+translation_example_la_SOURCES = translation_example.c
 
 autoaccept_la_LIBADD         = $(GLIB_LIBS)
 buddynote_la_LIBADD          = $(GLIB_LIBS)
============================================================
--- libpurple/plugins/translation_example.c	38d61d456cd2adf4e33f1d32c01ec3f00c2139e3
+++ libpurple/plugins/translation_example.c	c9f9b88181101806c7cb897e104319a89a44a292
@@ -1,7 +1,7 @@
 /*
  * Plugin Translation Example Plugin
  *
- * Copyright (C) 2007, John Bailey <rekkanoryo at cpw.pidgin.im>
+ * Copyright (C) 2007, John Bailey <rekkanoryo at pidgin.im>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -20,6 +20,11 @@
  *
  */
 
+/* Note that some of the things done in this plugin for the sake of being
+ * translatable may not make sense without some basic knowledge of how the GNU
+ * autoconf and automake tools work and provide information.  There will be a
+ * how-to document on our wiki to aid in this eventually. */
+
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
@@ -34,6 +39,27 @@
 # endif
 #endif
 
+/* This is all the preprocessor magic needed to make translation support work;
+ * it's essentially stolen from libpurple. */
+#ifdef ENABLE_NLS
+#  include <locale.h>
+#  include <libintl.h>
+#  define _(String) ((const char *)dgettext(PACKAGE, String))
+#  ifdef gettext_noop
+#    define N_(String) gettext_noop (String)
+#  else
+#    define N_(String) (String)
+#  endif
+#else
+#  include <locale.h>
+#  define N_(String) (String)
+#  ifndef _
+#    define _(String) ((const char *)String)
+#  endif
+#  define ngettext(Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural))
+#  define dngettext(Domain, Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural))
+#endif
+
 /* This is the required definition of PURPLE_PLUGINS as required for a plugin,
  * but we protect it with an #ifndef because config.h may define it for us
  * already and this would cause an unneeded compiler warning. */
@@ -43,11 +69,98 @@
 
 #include <notify.h>
 #include <plugin.h>
-#include <request.h>
 #include <version.h>
 
 #define PLUGIN_ID "core-translationexample"
 #define PLUGIN_AUTHOR "John Bailey <rekkanoryo at pidgin.im>"
+#define PLUGIN_WEBSITE "http://pidgin.im"
 
 static PurplePlugin *translation_example = NULL;
 
+static void
+action_cb(PurplePluginAction *action)
+{
+	purple_notify_message(translation_example, PURPLE_NOTIFY_MSG_INFO,
+		_("Plugin Translation Support Example"),
+		_("This is an example of how to use translation support in a plugin."),
+		NULL, NULL, NULL);
+}
+
+static GList *
+plugin_actions(PurplePlugin *plugin, gpointer context)
+{
+	return g_list_append(NULL, purple_plugin_action_new(_("Show Dialog"),
+				action_cb));
+}
+
+static PurplePluginInfo info = {
+	PURPLE_PLUGIN_MAGIC,
+	PURPLE_MAJOR_VERSION,
+	PURPLE_MINOR_VERSION,
+	PURPLE_PLUGIN_STANDARD,
+	NULL,
+	0,
+	NULL,
+	PURPLE_PRIORITY_DEFAULT,
+
+	PLUGIN_ID,
+	NULL,
+	DISPLAY_VERSION, /* Remember not to use this in your own plugins! */
+
+	/* Ordinarily we would use N_("some string") here, but in a third-party
+	 * plugin, we do things a bit differently to accomodate actually displaying
+	 * the translated messages.  We'll explain this below. */
+	NULL, /* see the comment above */
+	NULL, /* see the comment above */
+	PLUGIN_AUTHOR,
+	PLUGIN_WEBSITE,
+
+	NULL,
+	NULL,
+	NULL,
+
+	NULL,
+	NULL,
+	NULL,
+	plugin_actions,
+
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+static void
+init_plugin(PurplePlugin *plugin)
+{
+	/* The lines below are disabled with #if 0 because we don't want them to
+	 * take effect when this plugin is distributed with libpurple--in this case
+	 * we want to rely on libpurple/Pidgin's existing translations.  The lines
+	 * are shown here, however, because a plugin developer wishing to provide
+	 * translation abilities will need to use them to keep his/her plugin from
+	 * trying to use libpurple/Pidgin's translation database (which would most
+	 * likely not contain all the strings used in the plugin).  Plugin authors
+	 * following this example would remove the #if 0 and the #endif, leaving
+	 * the remaining lines. */
+#if 0
+#  ifdef ENABLE_NLS
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset(PACKAGE, "UTF-8");
+#  endif
+#endif
+
+	/* I (rekkanoryo) have encountered issues during my time developing for the
+	 * Purple Plugin Pack where translators have discovered that, although the
+	 * name, summary, and description strings are marked as translatable with
+	 * N_(), the translated strings do not appear; the best solution that worked
+	 * was to actually assign these fields here in init_plugin() with _() to
+	 * ensure translation. */
+	info.name = _("Plugin Translation Example");
+	info.summary = _("Plugin Translation Support Example Plugin");
+	info.description = _("This plugin serves as an example to third-party "
+		"plugin authors who wish to include translation support in their plugins.");
+
+	translation_example = plugin; /* we need a handle for the notify call above */
+}
+
+PURPLE_INIT_PLUGIN(translation_example, init_plugin, info)


More information about the Commits mailing list