diff --git a/Makefile b/Makefile index 909a857..0b08b63 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = Surfer VERSION = 0.1.0 -SUBDIRS = data src +SUBDIRS = data po src RM = rm -f LN = ln -f TAR = tar -czvf @@ -24,6 +24,13 @@ dist: $(PACKAGE)-$(VERSION)/data/Makefile \ $(PACKAGE)-$(VERSION)/data/surfer.desktop \ $(PACKAGE)-$(VERSION)/data/project.conf \ + $(PACKAGE)-$(VERSION)/po/Makefile \ + $(PACKAGE)-$(VERSION)/po/gettext.sh \ + $(PACKAGE)-$(VERSION)/po/POTFILES \ + $(PACKAGE)-$(VERSION)/po/de.po \ + $(PACKAGE)-$(VERSION)/po/es.po \ + $(PACKAGE)-$(VERSION)/po/fr.po \ + $(PACKAGE)-$(VERSION)/po/project.conf \ $(PACKAGE)-$(VERSION)/src/download.c \ $(PACKAGE)-$(VERSION)/src/surfer.c \ $(PACKAGE)-$(VERSION)/src/ghtml.c \ @@ -47,6 +54,7 @@ dist: $(PACKAGE)-$(VERSION)/Makefile \ $(PACKAGE)-$(VERSION)/COPYING \ $(PACKAGE)-$(VERSION)/config.h \ + $(PACKAGE)-$(VERSION)/config.sh \ $(PACKAGE)-$(VERSION)/project.conf $(RM) $(PACKAGE)-$(VERSION) diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..02383d9 --- /dev/null +++ b/config.sh @@ -0,0 +1,5 @@ +PACKAGE="Surfer" +VERSION="0.1.0" + +PREFIX="/usr/local" +LIBDIR="${PREFIX}/lib" diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..ea96669 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,47 @@ +TARGETS = Surfer.pot de.po de.mo es.po es.mo fr.po fr.mo +RM = rm -f +LN = ln -f +MKDIR = mkdir -p +INSTALL = install + + +all: $(TARGETS) + +Surfer.pot: POTFILES + ./gettext.sh "Surfer.pot" + +de.po: Surfer.pot + ./gettext.sh "de.po" + +de.mo: de.po + ./gettext.sh "de.mo" + +es.po: Surfer.pot + ./gettext.sh "es.po" + +es.mo: es.po + ./gettext.sh "es.mo" + +fr.po: Surfer.pot + ./gettext.sh "fr.po" + +fr.mo: fr.po + ./gettext.sh "fr.mo" + +clean: + $(RM) $(Surfer.pot_OBJS) $(de.po_OBJS) $(de.mo_OBJS) $(es.po_OBJS) $(es.mo_OBJS) $(fr.po_OBJS) $(fr.mo_OBJS) + +distclean: clean + $(RM) $(TARGETS) + +install: all + ./gettext.sh -p "$(PREFIX)" install "de.mo" + ./gettext.sh -p "$(PREFIX)" install "es.mo" + ./gettext.sh -p "$(PREFIX)" install "fr.mo" + +uninstall: + ./gettext.sh -p "$(PREFIX)" uninstall "de.mo" + ./gettext.sh -p "$(PREFIX)" uninstall "es.mo" + ./gettext.sh -p "$(PREFIX)" uninstall "fr.mo" + +.PHONY: all clean distclean install uninstall diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 0000000..64d56ee --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,2 @@ +../src/main.c +../src/surfer.c diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000..1e65e62 --- /dev/null +++ b/po/de.po @@ -0,0 +1,77 @@ +# German translations for Surfer package. +# Copyright (c) 2010 Pierre Pronchery +# This file is distributed under the same license as the Surfer package. +# Pierre Pronchery , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: Surfer 0.1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-04-01 20:00+0200\n" +"PO-Revision-Date: 2010-04-01 19:40+0200\n" +"Last-Translator: Pierre Pronchery \n" +"Language-Team: German\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-15\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: ../src/main.c:42 +msgid "Usage: surfer [URL]\n" +msgstr "" + +#: ../src/surfer.c:230 +msgid " Location: " +msgstr "" + +#: ../src/surfer.c:252 +msgid "Could not initialize HTML renderer" +msgstr "" + +#: ../src/surfer.c:453 ../src/surfer.c:456 +msgid "Question" +msgstr "" + +#: ../src/surfer.c:473 ../src/surfer.c:707 +msgid "Save file as..." +msgstr "" + +#: ../src/surfer.c:504 ../src/surfer.c:507 +msgid "Error" +msgstr "" + +#: ../src/surfer.c:506 +msgid "Unknown error" +msgstr "" + +#: ../src/surfer.c:527 +msgid "Find text" +msgstr "" + +#: ../src/surfer.c:534 +msgid "Text:" +msgstr "" + +#: ../src/surfer.c:543 +msgid "Case-sensitive" +msgstr "" + +#: ../src/surfer.c:546 +msgid "Wrap" +msgstr "" + +#: ../src/surfer.c:574 +msgid "Text not found" +msgstr "" + +#: ../src/surfer.c:648 +msgid "Open file..." +msgstr "" + +#: ../src/surfer.c:831 +msgid "Web surfer - Source of " +msgstr "" + +#: ../src/surfer.c:873 ../src/surfer.c:876 +msgid "Warning" +msgstr "" diff --git a/po/es.po b/po/es.po new file mode 100644 index 0000000..d419713 --- /dev/null +++ b/po/es.po @@ -0,0 +1,77 @@ +# Spanish translations for Surfer package. +# Copyright (c) 2010 Pierre Pronchery +# This file is distributed under the same license as the Surfer package. +# Pierre Pronchery , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: Surfer 0.1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-04-01 20:00+0200\n" +"PO-Revision-Date: 2010-04-01 19:40+0200\n" +"Last-Translator: Pierre Pronchery \n" +"Language-Team: Spanish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-15\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: ../src/main.c:42 +msgid "Usage: surfer [URL]\n" +msgstr "" + +#: ../src/surfer.c:230 +msgid " Location: " +msgstr "" + +#: ../src/surfer.c:252 +msgid "Could not initialize HTML renderer" +msgstr "" + +#: ../src/surfer.c:453 ../src/surfer.c:456 +msgid "Question" +msgstr "" + +#: ../src/surfer.c:473 ../src/surfer.c:707 +msgid "Save file as..." +msgstr "" + +#: ../src/surfer.c:504 ../src/surfer.c:507 +msgid "Error" +msgstr "" + +#: ../src/surfer.c:506 +msgid "Unknown error" +msgstr "" + +#: ../src/surfer.c:527 +msgid "Find text" +msgstr "" + +#: ../src/surfer.c:534 +msgid "Text:" +msgstr "" + +#: ../src/surfer.c:543 +msgid "Case-sensitive" +msgstr "" + +#: ../src/surfer.c:546 +msgid "Wrap" +msgstr "" + +#: ../src/surfer.c:574 +msgid "Text not found" +msgstr "" + +#: ../src/surfer.c:648 +msgid "Open file..." +msgstr "" + +#: ../src/surfer.c:831 +msgid "Web surfer - Source of " +msgstr "" + +#: ../src/surfer.c:873 ../src/surfer.c:876 +msgid "Warning" +msgstr "" diff --git a/po/fr.po b/po/fr.po new file mode 100644 index 0000000..48cd770 --- /dev/null +++ b/po/fr.po @@ -0,0 +1,77 @@ +# French translations for Surfer package. +# Copyright (c) 2010 Pierre Pronchery +# This file is distributed under the same license as the Surfer package. +# Pierre Pronchery , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: Surfer 0.1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-04-01 20:00+0200\n" +"PO-Revision-Date: 2010-04-01 19:40+0200\n" +"Last-Translator: Pierre Pronchery \n" +"Language-Team: French\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-15\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: ../src/main.c:42 +msgid "Usage: surfer [URL]\n" +msgstr "Usage: surfer [URL]\n" + +#: ../src/surfer.c:230 +msgid " Location: " +msgstr " Adresse: " + +#: ../src/surfer.c:252 +msgid "Could not initialize HTML renderer" +msgstr "" + +#: ../src/surfer.c:453 ../src/surfer.c:456 +msgid "Question" +msgstr "Question" + +#: ../src/surfer.c:473 ../src/surfer.c:707 +msgid "Save file as..." +msgstr "Enregistrer sous..." + +#: ../src/surfer.c:504 ../src/surfer.c:507 +msgid "Error" +msgstr "Erreur" + +#: ../src/surfer.c:506 +msgid "Unknown error" +msgstr "Erreur inconnue" + +#: ../src/surfer.c:527 +msgid "Find text" +msgstr "Chercher du texte" + +#: ../src/surfer.c:534 +msgid "Text:" +msgstr "Texte: " + +#: ../src/surfer.c:543 +msgid "Case-sensitive" +msgstr "" + +#: ../src/surfer.c:546 +msgid "Wrap" +msgstr "" + +#: ../src/surfer.c:574 +msgid "Text not found" +msgstr "Texte non trouvé" + +#: ../src/surfer.c:648 +msgid "Open file..." +msgstr "Ouvrir un fichier..." + +#: ../src/surfer.c:831 +msgid "Web surfer - Source of " +msgstr "Web surfer - Source de " + +#: ../src/surfer.c:873 ../src/surfer.c:876 +msgid "Warning" +msgstr "Avertissement" diff --git a/po/gettext.sh b/po/gettext.sh new file mode 100755 index 0000000..aca3be4 --- /dev/null +++ b/po/gettext.sh @@ -0,0 +1,98 @@ +#!/bin/sh +#$Id$ + + + +#variables +. "../config.sh" +DEBUG="_debug" +INSTALL="install -m 0644" +LOCALEDIR="$PREFIX/share/locale" +MKDIR="mkdir -p" +MSGFMT="msgfmt" +MSGINIT="msginit" +MSGMERGE="msgmerge" +POTFILES="POTFILES" +XGETTEXT="xgettext --force-po" + + +#functions +#usage +_usage() +{ + echo "Usage: ./gettext.sh target" 1>&2 + return 1 +} + + +#debug +_debug() +{ + echo $@ + $@ +} + + +#gettext_mo +_gettext_mo() +{ + lang="$2" + + $DEBUG $MSGFMT -c -v -o "$lang.mo" "$lang.po" || return 1 +} + + +#gettext_po +_gettext_po() +{ + package="$1" + lang="$2" + + if [ -f "$lang.po" ]; then + $DEBUG $MSGMERGE -U "$lang.po" "$package.pot" || return 1 + return 0 + fi + $DEBUG $MSGINIT -l "$lang" -o "$lang.po" -i "$package.pot" \ + || return 1 +} + + +#gettext_pot +_gettext_pot() +{ + package="$1" + + $DEBUG $XGETTEXT -d "$package" -o "$package.pot" --keyword="_" \ + -f "$POTFILES" || return 1 +} + + +#main +if [ $# -eq 4 -a "$1" = "-p" -a "$3" = "install" ]; then + #PREFIX="$2" XXX doesn't work atm + lang="${4%%.mo}" + + $DEBUG $MKDIR "$LOCALEDIR/$lang/LC_MESSAGES" || exit 2 + $DEBUG $INSTALL "$4" "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \ + || exit 2 + exit 0 +fi +if [ $# -ne 1 ]; then + _usage + exit $? +fi +case "$1" in + *.mo) + _gettext_mo "$PACKAGE" "${1%%.mo}" || exit 2 + ;; + *.po) + _gettext_po "$PACKAGE" "${1%%.po}" || exit 2 + ;; + *.pot) + _gettext_pot "${1%%.pot}" || exit 2 + ;; + *) + exit 2 + ;; +esac +exit 0 diff --git a/po/project.conf b/po/project.conf new file mode 100644 index 0000000..acb4695 --- /dev/null +++ b/po/project.conf @@ -0,0 +1,40 @@ +targets=Surfer.pot,de.po,de.mo,es.po,es.mo,fr.po,fr.mo +dist=Makefile,gettext.sh,POTFILES,de.po,es.po,fr.po + +[Surfer.pot] +type=script +script=./gettext.sh +depends=POTFILES + +[de.po] +type=script +script=./gettext.sh +depends=Surfer.pot + +[de.mo] +type=script +script=./gettext.sh +install= +depends=de.po + +[es.po] +type=script +script=./gettext.sh +depends=Surfer.pot + +[es.mo] +type=script +script=./gettext.sh +install= +depends=es.po + +[fr.po] +type=script +script=./gettext.sh +depends=Surfer.pot + +[fr.mo] +type=script +script=./gettext.sh +install= +depends=fr.po diff --git a/project.conf b/project.conf index b2fbb93..d6c7f04 100644 --- a/project.conf +++ b/project.conf @@ -1,6 +1,6 @@ package=Surfer version=0.1.0 -config=h -dist=Makefile,COPYING,config.h +config=h,sh +dist=Makefile,COPYING,config.h,config.sh -subdirs=data,src +subdirs=data,po,src diff --git a/src/main.c b/src/main.c index e13132b..3963cbe 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2009 Pierre Pronchery */ +/* Copyright (c) 2010 Pierre Pronchery */ /* This file is part of DeforaOS Desktop Surfer */ /* Surfer is free software; you can redistribute it and/or modify it under the * terms of the GNU General Public License version 2 as published by the Free @@ -17,13 +17,29 @@ #include #include +#include +#include #include "surfer.h" +#include "../config.h" +#define _(string) gettext(string) + + +/* constants */ +#ifndef PREFIX +# define PREFIX "/usr/local" +#endif +#ifndef DATADIR +# define DATADIR PREFIX "/share" +#endif +#ifndef LOCALEDIR +# define LOCALEDIR DATADIR "/locale" +#endif /* usage */ static int _usage(void) { - fputs("Usage: surfer [url]\n", stderr); + fputs(_("Usage: surfer [URL]\n"), stderr); return 1; } @@ -34,6 +50,9 @@ int main(int argc, char * argv[]) int o; Surfer * surfer; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); #if defined(WITH_GTKHTML) || defined(WITH_GTKTEXTVIEW) || defined(WITH_WEBKIT) if(g_thread_supported() == FALSE) g_thread_init(NULL); diff --git a/src/surfer.c b/src/surfer.c index 40cbeb3..c58a5ad 100644 --- a/src/surfer.c +++ b/src/surfer.c @@ -18,12 +18,14 @@ #include #include #include +#include #include #include #include "callbacks.h" #include "ghtml.h" #include "surfer.h" #include "common.h" +#define _(string) gettext(string) /* Surfer */ @@ -225,7 +227,7 @@ Surfer * surfer_new(char const * url) gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); #ifndef EMBEDDED toolitem = gtk_tool_item_new(); - widget = gtk_label_new(" Location: "); + widget = gtk_label_new(_(" Location: ")); gtk_container_add(GTK_CONTAINER(toolitem), widget); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1); #endif @@ -247,7 +249,7 @@ Surfer * surfer_new(char const * url) /* view */ if((surfer->view = ghtml_new(surfer)) == NULL) { - surfer_error(NULL, "Could not initialize HTML renderer", 0); + surfer_error(NULL, _("Could not initialize HTML renderer"), 0); surfer_delete(surfer); return NULL; } @@ -448,10 +450,10 @@ int surfer_confirm(Surfer * surfer, char const * message) ? GTK_WINDOW(surfer->window) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", - "Question"); + _("Question")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", message); - gtk_window_set_title(GTK_WINDOW(dialog), "Question"); + gtk_window_set_title(GTK_WINDOW(dialog), _("Question")); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( gtk_widget_destroy), NULL); ret = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -468,7 +470,7 @@ void surfer_download(Surfer * surfer, char const * url, char const * suggested) char * argv[] = { "download", "-O", NULL, NULL, NULL }; GError * error = NULL; - dialog = gtk_file_chooser_dialog_new("Save file as...", + dialog = gtk_file_chooser_dialog_new(_("Save file as..."), GTK_WINDOW(surfer->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, @@ -499,10 +501,10 @@ int surfer_error(Surfer * surfer, char const * message, int ret) dialog = gtk_message_dialog_new((surfer != NULL) ? GTK_WINDOW(surfer->window) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", "Error"); + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Error")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), - "%s", (message != NULL) ? message : "Unknown error"); - gtk_window_set_title(GTK_WINDOW(dialog), "Error"); + "%s", (message != NULL) ? message : _("Unknown error")); + gtk_window_set_title(GTK_WINDOW(dialog), _("Error")); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( gtk_widget_destroy), NULL); gtk_widget_show(dialog); @@ -522,14 +524,14 @@ void surfer_find(Surfer * surfer, char const * text) if(surfer->fi_dialog == NULL) { - surfer->fi_dialog = gtk_dialog_new_with_buttons("Find text", + surfer->fi_dialog = gtk_dialog_new_with_buttons(_("Find text"), GTK_WINDOW(surfer->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_FIND, GTK_RESPONSE_ACCEPT, NULL); vbox = GTK_DIALOG(surfer->fi_dialog)->vbox; hbox = gtk_hbox_new(FALSE, 0); - widget = gtk_label_new("Text:"); + widget = gtk_label_new(_("Text:")); gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0); surfer->fi_text = gtk_entry_new(); g_signal_connect(G_OBJECT(surfer->fi_text), "activate", @@ -538,10 +540,10 @@ void surfer_find(Surfer * surfer, char const * text) 4); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 4); surfer->fi_case = gtk_check_button_new_with_label( - "Case-sensitive"); + _("Case-sensitive")); gtk_box_pack_start(GTK_BOX(vbox), surfer->fi_case, TRUE, TRUE, 4); - surfer->fi_wrap = gtk_check_button_new_with_label("Wrap"); + surfer->fi_wrap = gtk_check_button_new_with_label(_("Wrap")); gtk_box_pack_start(GTK_BOX(vbox), surfer->fi_wrap, TRUE, TRUE, 4); gtk_widget_show_all(vbox); @@ -569,7 +571,7 @@ static void _on_find_activate(GtkWidget * widget, gpointer data) surfer->fi_wrap)); if(ghtml_find(surfer->view, text, sensitive, wrap) == TRUE) return; - surfer_error(surfer, "Text not found", 0); + surfer_error(surfer, _("Text not found"), 0); } static void _on_find_response(GtkWidget * widget, gint response, gpointer data) @@ -643,7 +645,7 @@ void surfer_open_dialog(Surfer * surfer) GtkWidget * dialog; char * filename = NULL; - dialog = gtk_file_chooser_dialog_new("Open file...", + dialog = gtk_file_chooser_dialog_new(_("Open file..."), GTK_WINDOW(surfer->window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, @@ -702,7 +704,7 @@ void surfer_save(Surfer * surfer, char const * filename) return; /* XXX report error */ if(filename == NULL) { - dialog = gtk_file_chooser_dialog_new("Save file as...", + dialog = gtk_file_chooser_dialog_new(_("Save file as..."), GTK_WINDOW(surfer->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, @@ -826,7 +828,7 @@ void surfer_view_source(Surfer * surfer) GTK_ACCEL_VISIBLE, cc); gtk_window_add_accel_group(GTK_WINDOW(window), group); gtk_window_set_default_size(GTK_WINDOW(window), 640, 480); - snprintf(buf, sizeof(buf), "%s%s", "Web surfer - Source of ", + snprintf(buf, sizeof(buf), "%s%s", _("Web surfer - Source of "), surfer->url); gtk_window_set_title(GTK_WINDOW(window), buf); g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK( @@ -867,10 +869,11 @@ void surfer_warning(Surfer * surfer, char const * message) dialog = gtk_message_dialog_new((surfer != NULL) ? GTK_WINDOW(surfer->window) : NULL, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s", "Warning"); + GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s", + _("Warning")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", message); - gtk_window_set_title(GTK_WINDOW(dialog), "Warning"); + gtk_window_set_title(GTK_WINDOW(dialog), _("Warning")); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( gtk_widget_destroy), NULL); gtk_widget_show(dialog);