changeset 8:58a3312a1c59

add internationalization support add German translation --HG-- rename : pk-update-icon.desktop => pk-update-icon.desktop.in
author Guido Berhoerster <guido@berhoerster.name>
date Tue, 11 Oct 2011 17:07:49 +0200
parents 56a7ed833d0a
children 0e50d3652326
files AUTHORS Makefile main.c notify.c notify.h pk-update-icon.desktop pk-update-icon.desktop.in po/POTFILES.in po/de.po
diffstat 9 files changed, 111 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/AUTHORS	Tue Oct 11 17:07:49 2011 +0200
+++ b/AUTHORS	Tue Oct 11 17:07:49 2011 +0200
@@ -1,1 +1,2 @@
 Pavol Rusnak <stick@gk2.sk>
+Guido Berhoerster <gber@opensuse.org>
--- a/Makefile	Tue Oct 11 17:07:49 2011 +0200
+++ b/Makefile	Tue Oct 11 17:07:49 2011 +0200
@@ -2,10 +2,15 @@
 INSTALL.exec :=	$(INSTALL) -D -m 0755
 INSTALL.data :=	$(INSTALL) -D -m 0644
 SED :=		sed
+MSGFMT :=	msgfmt
+INTLTOOL_UPDATE :=	intltool-update
+INTLTOOL_MERGE :=	intltool-merge
 
 DESTDIR ?=
 prefix ?=	/usr/local
 bindir ?=	$(prefix)/bin
+datadir ?=	$(prefix)/share
+localedir ?=	$(datadir)/locale
 sysconfdir ?=	/etc
 xdgautostartdir ?=	$(sysconfdir)/xdg/autostart
 
@@ -13,19 +18,34 @@
 VERSION =	0.1
 OBJS =		main.o notify.o packagekit.o
 AUTOSTART_FILE =	$(PACKAGE).desktop
+MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
+POTFILE =	po/$(PACKAGE).pot
 CPPFLAGS :=	$(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) \
-		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
+		-DPACKAGE="\"$(PACKAGE)\"" \
+		-DLOCALEDIR="\"$(localedir)\""
 LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2)
 
 .DEFAULT_TARGET = all
 
 .PHONY: all clean install
 
-all: $(PACKAGE)
+all: $(PACKAGE) $(MOFILES) $(AUTOSTART_FILE)
 
 $(PACKAGE): $(OBJS)
 	$(LINK.o) $^ $(LDLIBS) -o $@
 
+$(POTFILE): po/POTFILES.in
+	cd po/ && $(INTLTOOL_UPDATE) --pot --gettext-package="$(PACKAGE)"
+
+pot: $(POTFILE)
+
+update-po: $(POTFILE)
+	cd po/ && for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
+		$(INTLTOOL_UPDATE) --dist --gettext-package="$(PACKAGE)" \
+				   $${lang}; \
+	done
+
 %.o: %.c
 	$(COMPILE.c) -MD -o $@ $<
 	@cp $*.d $*.P; \
@@ -33,12 +53,22 @@
 	       -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
 	rm -f $*.d
 
+%.desktop: %.desktop.in $(MOFILES)
+	$(INTLTOOL_MERGE) --desktop-style --utf8 po $< $@
+
+%.mo: %.po
+	$(MSGFMT) -o $@ $<
+
 install:
 	$(INSTALL.exec) $(PACKAGE) $(DESTDIR)$(bindir)/$(PACKAGE)
 	$(INSTALL.data) $(AUTOSTART_FILE) \
 			$(DESTDIR)$(xdgautostartdir)/$(AUTOSTART_FILE)
+	for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
+		$(INSTALL.data) po/$${lang}.mo \
+			$(DESTDIR)$(LOCALEDIR)/$${lang}/$(PACKAGE).mo; \
+	done
 
 clean:
-	-rm -f $(PACKAGE) $(OBJS)
+	rm -f $(PACKAGE) $(OBJS) $(POTFILE) $(MOFILES) $(AUTOSTART_FILE)
 
 -include $(patsubst %.o,%.P,$(OBJS))
--- a/main.c	Tue Oct 11 17:07:49 2011 +0200
+++ b/main.c	Tue Oct 11 17:07:49 2011 +0200
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
+ * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -21,6 +22,8 @@
 #include "main.h"
 #include "notify.h"
 #include "packagekit.h"
+#include <locale.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 struct UpdatesInfo info;
@@ -43,7 +46,7 @@
 {
 	GtkWidget *item;
 	GtkWidget *menu = gtk_menu_new();
-	item = gtk_menu_item_new_with_mnemonic("_Quit");
+	item = gtk_menu_item_new_with_mnemonic(_("_Quit"));
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 	g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data);
 	gtk_widget_show(item);
@@ -61,7 +64,7 @@
 	g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
 	g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL);
 	gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update");
-	gtk_status_icon_set_title(tray_icon, "Software Update");
+	gtk_status_icon_set_title(tray_icon, _("Software Update(s)"));
 	gtk_status_icon_set_visible(tray_icon, TRUE);
 	return tray_icon;
 }
@@ -84,6 +87,11 @@
 {
 	GtkStatusIcon *tray_icon;
 
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset(PACKAGE, "UTF-8");
+	textdomain(PACKAGE);
+
 	gtk_init(&argc, &argv);
 	tray_icon = create_tray_icon();
 	init_notify();
--- a/notify.c	Tue Oct 11 17:07:49 2011 +0200
+++ b/notify.c	Tue Oct 11 17:07:49 2011 +0200
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
+ * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -18,20 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <libnotify/notify.h>
 #include "notify.h"
 
-#define NOTIFY_NAME "Software Update"
-
 void init_notify()
 {
-	notify_init(NOTIFY_NAME);
+	notify_init(PACKAGE);
 }
 
 void send_notify(struct UpdatesInfo *info)
 {
 	NotifyNotification *ntfy;
-	ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
+	ntfy = notify_notification_new(_("Software Update(s)"), notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
 	notify_notification_set_timeout(ntfy, 3000);
 	notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL);
 	notify_notification_show(ntfy, NULL);
@@ -41,9 +39,9 @@
 {
 	static char buf[128];
 	if (info->critical > 0) {
-		snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical);
+		snprintf(buf, sizeof(buf), _("There are %d software updates available, %d of them critical."), info->normal + info->critical, info->critical);
 	} else {
-		snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal);
+		snprintf(buf, sizeof(buf), _("There are %d software updates available."), info->normal);
 	}
 	return buf;
 }
--- a/notify.h	Tue Oct 11 17:07:49 2011 +0200
+++ b/notify.h	Tue Oct 11 17:07:49 2011 +0200
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
+ * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -21,6 +22,9 @@
 #ifndef NOTIFY_H
 #define NOTIFY_H
 
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libnotify/notify.h>
 #include "main.h"
 
 void init_notify();
--- a/pk-update-icon.desktop	Tue Oct 11 17:07:49 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-[Desktop Entry]
-Name=PackageKit Update Applet
-GenericName=Update Applet
-Comment=PackageKit Update Applet
-Icon=system-software-update
-Exec=pk-update-icon
-Terminal=false
-Type=Application
-Categories=Utility;GTK;TrayIcon;
-OnlyShowIn=XFCE;LXDE;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pk-update-icon.desktop.in	Tue Oct 11 17:07:49 2011 +0200
@@ -0,0 +1,10 @@
+[Desktop Entry]
+_Name=PackageKit Update Applet
+_GenericName=Update Applet
+_Comment=PackageKit Update Applet
+Icon=system-software-update
+Exec=pk-update-icon
+Terminal=false
+Type=Application
+Categories=Utility;GTK;TrayIcon;
+OnlyShowIn=XFCE;LXDE;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/po/POTFILES.in	Tue Oct 11 17:07:49 2011 +0200
@@ -0,0 +1,4 @@
+main.c
+notify.c
+packagekit.c
+pk-update-icon.desktop.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/po/de.po	Tue Oct 11 17:07:49 2011 +0200
@@ -0,0 +1,44 @@
+# pk-update-icon
+# Copyright (C) 2011 Pavol Rusnak, Guido Berhoerster
+# This file is distributed under the same license as the pk-update-icon package.
+# Guido Berhoerster <guido@berhoerster.name>, 2011.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: pk-update-icon 0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2011-10-10 19:19+0200\n"
+"PO-Revision-Date: 2011-10-10 19:21+0200\n"
+"Last-Translator: Guido Berhoerster <gber@opensuse.org>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: ../main.c:49
+msgid "_Quit"
+msgstr "_Verlassen"
+
+#: ../main.c:67 ../notify.c:32
+msgid "Software Update(s)"
+msgstr "Software Update(s)"
+
+#: ../notify.c:42
+#, c-format
+msgid "There are %d software updates available, %d of them critical."
+msgstr "%d Software Updates sind verfügbar, %d davon sind kritisch."
+
+#: ../notify.c:44
+#, c-format
+msgid "There are %d software updates available."
+msgstr "%d Software Updates sind verfügbar."
+
+#: ../pk-update-icon.desktop.in.h:1
+msgid "PackageKit Update Applet"
+msgstr "PackageKit Update Applet"
+
+#: ../pk-update-icon.desktop.in.h:2
+msgid "Update Applet"
+msgstr "Update Applet"