projects/pk-update-icon

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 Oct 11 17:07:49 2011 +0200 (2011-10-11)
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
line diff
     1.1 --- a/AUTHORS	Tue Oct 11 17:07:49 2011 +0200
     1.2 +++ b/AUTHORS	Tue Oct 11 17:07:49 2011 +0200
     1.3 @@ -1,1 +1,2 @@
     1.4  Pavol Rusnak <stick@gk2.sk>
     1.5 +Guido Berhoerster <gber@opensuse.org>
     2.1 --- a/Makefile	Tue Oct 11 17:07:49 2011 +0200
     2.2 +++ b/Makefile	Tue Oct 11 17:07:49 2011 +0200
     2.3 @@ -2,10 +2,15 @@
     2.4  INSTALL.exec :=	$(INSTALL) -D -m 0755
     2.5  INSTALL.data :=	$(INSTALL) -D -m 0644
     2.6  SED :=		sed
     2.7 +MSGFMT :=	msgfmt
     2.8 +INTLTOOL_UPDATE :=	intltool-update
     2.9 +INTLTOOL_MERGE :=	intltool-merge
    2.10  
    2.11  DESTDIR ?=
    2.12  prefix ?=	/usr/local
    2.13  bindir ?=	$(prefix)/bin
    2.14 +datadir ?=	$(prefix)/share
    2.15 +localedir ?=	$(datadir)/locale
    2.16  sysconfdir ?=	/etc
    2.17  xdgautostartdir ?=	$(sysconfdir)/xdg/autostart
    2.18  
    2.19 @@ -13,19 +18,34 @@
    2.20  VERSION =	0.1
    2.21  OBJS =		main.o notify.o packagekit.o
    2.22  AUTOSTART_FILE =	$(PACKAGE).desktop
    2.23 +MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
    2.24 +POTFILE =	po/$(PACKAGE).pot
    2.25  CPPFLAGS :=	$(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) \
    2.26 -		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
    2.27 +		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
    2.28 +		-DPACKAGE="\"$(PACKAGE)\"" \
    2.29 +		-DLOCALEDIR="\"$(localedir)\""
    2.30  LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2)
    2.31  
    2.32  .DEFAULT_TARGET = all
    2.33  
    2.34  .PHONY: all clean install
    2.35  
    2.36 -all: $(PACKAGE)
    2.37 +all: $(PACKAGE) $(MOFILES) $(AUTOSTART_FILE)
    2.38  
    2.39  $(PACKAGE): $(OBJS)
    2.40  	$(LINK.o) $^ $(LDLIBS) -o $@
    2.41  
    2.42 +$(POTFILE): po/POTFILES.in
    2.43 +	cd po/ && $(INTLTOOL_UPDATE) --pot --gettext-package="$(PACKAGE)"
    2.44 +
    2.45 +pot: $(POTFILE)
    2.46 +
    2.47 +update-po: $(POTFILE)
    2.48 +	cd po/ && for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
    2.49 +		$(INTLTOOL_UPDATE) --dist --gettext-package="$(PACKAGE)" \
    2.50 +				   $${lang}; \
    2.51 +	done
    2.52 +
    2.53  %.o: %.c
    2.54  	$(COMPILE.c) -MD -o $@ $<
    2.55  	@cp $*.d $*.P; \
    2.56 @@ -33,12 +53,22 @@
    2.57  	       -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
    2.58  	rm -f $*.d
    2.59  
    2.60 +%.desktop: %.desktop.in $(MOFILES)
    2.61 +	$(INTLTOOL_MERGE) --desktop-style --utf8 po $< $@
    2.62 +
    2.63 +%.mo: %.po
    2.64 +	$(MSGFMT) -o $@ $<
    2.65 +
    2.66  install:
    2.67  	$(INSTALL.exec) $(PACKAGE) $(DESTDIR)$(bindir)/$(PACKAGE)
    2.68  	$(INSTALL.data) $(AUTOSTART_FILE) \
    2.69  			$(DESTDIR)$(xdgautostartdir)/$(AUTOSTART_FILE)
    2.70 +	for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
    2.71 +		$(INSTALL.data) po/$${lang}.mo \
    2.72 +			$(DESTDIR)$(LOCALEDIR)/$${lang}/$(PACKAGE).mo; \
    2.73 +	done
    2.74  
    2.75  clean:
    2.76 -	-rm -f $(PACKAGE) $(OBJS)
    2.77 +	rm -f $(PACKAGE) $(OBJS) $(POTFILE) $(MOFILES) $(AUTOSTART_FILE)
    2.78  
    2.79  -include $(patsubst %.o,%.P,$(OBJS))
     3.1 --- a/main.c	Tue Oct 11 17:07:49 2011 +0200
     3.2 +++ b/main.c	Tue Oct 11 17:07:49 2011 +0200
     3.3 @@ -1,5 +1,6 @@
     3.4  /*
     3.5   * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
     3.6 + * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
     3.7   *
     3.8   * Licensed under the GNU General Public License Version 2
     3.9   *
    3.10 @@ -21,6 +22,8 @@
    3.11  #include "main.h"
    3.12  #include "notify.h"
    3.13  #include "packagekit.h"
    3.14 +#include <locale.h>
    3.15 +#include <glib/gi18n.h>
    3.16  #include <gtk/gtk.h>
    3.17  
    3.18  struct UpdatesInfo info;
    3.19 @@ -43,7 +46,7 @@
    3.20  {
    3.21  	GtkWidget *item;
    3.22  	GtkWidget *menu = gtk_menu_new();
    3.23 -	item = gtk_menu_item_new_with_mnemonic("_Quit");
    3.24 +	item = gtk_menu_item_new_with_mnemonic(_("_Quit"));
    3.25  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    3.26  	g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_main_quit), user_data);
    3.27  	gtk_widget_show(item);
    3.28 @@ -61,7 +64,7 @@
    3.29  	g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
    3.30  	g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL);
    3.31  	gtk_status_icon_set_from_icon_name(tray_icon, "system-software-update");
    3.32 -	gtk_status_icon_set_title(tray_icon, "Software Update");
    3.33 +	gtk_status_icon_set_title(tray_icon, _("Software Update(s)"));
    3.34  	gtk_status_icon_set_visible(tray_icon, TRUE);
    3.35  	return tray_icon;
    3.36  }
    3.37 @@ -84,6 +87,11 @@
    3.38  {
    3.39  	GtkStatusIcon *tray_icon;
    3.40  
    3.41 +	setlocale(LC_ALL, "");
    3.42 +	bindtextdomain(PACKAGE, LOCALEDIR);
    3.43 +	bind_textdomain_codeset(PACKAGE, "UTF-8");
    3.44 +	textdomain(PACKAGE);
    3.45 +
    3.46  	gtk_init(&argc, &argv);
    3.47  	tray_icon = create_tray_icon();
    3.48  	init_notify();
     4.1 --- a/notify.c	Tue Oct 11 17:07:49 2011 +0200
     4.2 +++ b/notify.c	Tue Oct 11 17:07:49 2011 +0200
     4.3 @@ -1,5 +1,6 @@
     4.4  /*
     4.5   * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
     4.6 + * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
     4.7   *
     4.8   * Licensed under the GNU General Public License Version 2
     4.9   *
    4.10 @@ -18,20 +19,17 @@
    4.11   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    4.12   */
    4.13  
    4.14 -#include <libnotify/notify.h>
    4.15  #include "notify.h"
    4.16  
    4.17 -#define NOTIFY_NAME "Software Update"
    4.18 -
    4.19  void init_notify()
    4.20  {
    4.21 -	notify_init(NOTIFY_NAME);
    4.22 +	notify_init(PACKAGE);
    4.23  }
    4.24  
    4.25  void send_notify(struct UpdatesInfo *info)
    4.26  {
    4.27  	NotifyNotification *ntfy;
    4.28 -	ntfy = notify_notification_new(NOTIFY_NAME, notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
    4.29 +	ntfy = notify_notification_new(_("Software Update(s)"), notify_text(info), info->critical > 0 ? "software-update-urgent" : "software-update-available");
    4.30  	notify_notification_set_timeout(ntfy, 3000);
    4.31  	notify_notification_set_urgency(ntfy, info->critical > 0 ? NOTIFY_URGENCY_CRITICAL : NOTIFY_URGENCY_NORMAL);
    4.32  	notify_notification_show(ntfy, NULL);
    4.33 @@ -41,9 +39,9 @@
    4.34  {
    4.35  	static char buf[128];
    4.36  	if (info->critical > 0) {
    4.37 -		snprintf(buf, sizeof(buf), "There are %d software updates available, %d of them critical.", info->normal + info->critical, info->critical);
    4.38 +		snprintf(buf, sizeof(buf), _("There are %d software updates available, %d of them critical."), info->normal + info->critical, info->critical);
    4.39  	} else {
    4.40 -		snprintf(buf, sizeof(buf), "There are %d software updates available.", info->normal);
    4.41 +		snprintf(buf, sizeof(buf), _("There are %d software updates available."), info->normal);
    4.42  	}
    4.43  	return buf;
    4.44  }
     5.1 --- a/notify.h	Tue Oct 11 17:07:49 2011 +0200
     5.2 +++ b/notify.h	Tue Oct 11 17:07:49 2011 +0200
     5.3 @@ -1,5 +1,6 @@
     5.4  /*
     5.5   * Copyright (C) 2011 Pavol Rusnak <stick@gk2.sk>
     5.6 + * Copyright (C) 2011 Guido Berhoerster <gber@opensuse.org>
     5.7   *
     5.8   * Licensed under the GNU General Public License Version 2
     5.9   *
    5.10 @@ -21,6 +22,9 @@
    5.11  #ifndef NOTIFY_H
    5.12  #define NOTIFY_H
    5.13  
    5.14 +#include <glib.h>
    5.15 +#include <glib/gi18n.h>
    5.16 +#include <libnotify/notify.h>
    5.17  #include "main.h"
    5.18  
    5.19  void init_notify();
     6.1 --- a/pk-update-icon.desktop	Tue Oct 11 17:07:49 2011 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,10 +0,0 @@
     6.4 -[Desktop Entry]
     6.5 -Name=PackageKit Update Applet
     6.6 -GenericName=Update Applet
     6.7 -Comment=PackageKit Update Applet
     6.8 -Icon=system-software-update
     6.9 -Exec=pk-update-icon
    6.10 -Terminal=false
    6.11 -Type=Application
    6.12 -Categories=Utility;GTK;TrayIcon;
    6.13 -OnlyShowIn=XFCE;LXDE;
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/pk-update-icon.desktop.in	Tue Oct 11 17:07:49 2011 +0200
     7.3 @@ -0,0 +1,10 @@
     7.4 +[Desktop Entry]
     7.5 +_Name=PackageKit Update Applet
     7.6 +_GenericName=Update Applet
     7.7 +_Comment=PackageKit Update Applet
     7.8 +Icon=system-software-update
     7.9 +Exec=pk-update-icon
    7.10 +Terminal=false
    7.11 +Type=Application
    7.12 +Categories=Utility;GTK;TrayIcon;
    7.13 +OnlyShowIn=XFCE;LXDE;
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/po/POTFILES.in	Tue Oct 11 17:07:49 2011 +0200
     8.3 @@ -0,0 +1,4 @@
     8.4 +main.c
     8.5 +notify.c
     8.6 +packagekit.c
     8.7 +pk-update-icon.desktop.in
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/po/de.po	Tue Oct 11 17:07:49 2011 +0200
     9.3 @@ -0,0 +1,44 @@
     9.4 +# pk-update-icon
     9.5 +# Copyright (C) 2011 Pavol Rusnak, Guido Berhoerster
     9.6 +# This file is distributed under the same license as the pk-update-icon package.
     9.7 +# Guido Berhoerster <guido@berhoerster.name>, 2011.
     9.8 +#
     9.9 +msgid ""
    9.10 +msgstr ""
    9.11 +"Project-Id-Version: pk-update-icon 0.1\n"
    9.12 +"Report-Msgid-Bugs-To: \n"
    9.13 +"POT-Creation-Date: 2011-10-10 19:19+0200\n"
    9.14 +"PO-Revision-Date: 2011-10-10 19:21+0200\n"
    9.15 +"Last-Translator: Guido Berhoerster <gber@opensuse.org>\n"
    9.16 +"Language-Team: German\n"
    9.17 +"Language: de\n"
    9.18 +"MIME-Version: 1.0\n"
    9.19 +"Content-Type: text/plain; charset=UTF-8\n"
    9.20 +"Content-Transfer-Encoding: 8bit\n"
    9.21 +"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    9.22 +
    9.23 +#: ../main.c:49
    9.24 +msgid "_Quit"
    9.25 +msgstr "_Verlassen"
    9.26 +
    9.27 +#: ../main.c:67 ../notify.c:32
    9.28 +msgid "Software Update(s)"
    9.29 +msgstr "Software Update(s)"
    9.30 +
    9.31 +#: ../notify.c:42
    9.32 +#, c-format
    9.33 +msgid "There are %d software updates available, %d of them critical."
    9.34 +msgstr "%d Software Updates sind verfügbar, %d davon sind kritisch."
    9.35 +
    9.36 +#: ../notify.c:44
    9.37 +#, c-format
    9.38 +msgid "There are %d software updates available."
    9.39 +msgstr "%d Software Updates sind verfügbar."
    9.40 +
    9.41 +#: ../pk-update-icon.desktop.in.h:1
    9.42 +msgid "PackageKit Update Applet"
    9.43 +msgstr "PackageKit Update Applet"
    9.44 +
    9.45 +#: ../pk-update-icon.desktop.in.h:2
    9.46 +msgid "Update Applet"
    9.47 +msgstr "Update Applet"