From 7506cee30d2c1dfdc34fd8607994103577a35b7a Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 20 May 2012 12:41:33 +0000 Subject: [PATCH] Translated the Keyboard project --- Makefile | 8 ++- config.sh | 5 ++ po/.cvsignore | 2 + po/Makefile | 30 +++++++++ po/POTFILES | 2 + po/fr.po | 45 ++++++++++++++ po/gettext.sh | 160 ++++++++++++++++++++++++++++++++++++++++++++++++ po/project.conf | 13 ++++ project.conf | 6 +- src/keyboard.c | 17 ++--- src/main.c | 24 +++++++- 11 files changed, 299 insertions(+), 13 deletions(-) create mode 100644 config.sh create mode 100644 po/.cvsignore create mode 100644 po/Makefile create mode 100644 po/POTFILES create mode 100644 po/fr.po create mode 100755 po/gettext.sh create mode 100644 po/project.conf diff --git a/Makefile b/Makefile index c6c0c71..b28e0e5 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = Keyboard VERSION = 0.2.0 -SUBDIRS = data include src tools +SUBDIRS = data include po src tools RM ?= rm -f LN ?= ln -f TAR ?= tar -czvf @@ -27,6 +27,11 @@ dist: $(PACKAGE)-$(VERSION)/include/Keyboard.h \ $(PACKAGE)-$(VERSION)/include/Makefile \ $(PACKAGE)-$(VERSION)/include/project.conf \ + $(PACKAGE)-$(VERSION)/po/Makefile \ + $(PACKAGE)-$(VERSION)/po/gettext.sh \ + $(PACKAGE)-$(VERSION)/po/POTFILES \ + $(PACKAGE)-$(VERSION)/po/fr.po \ + $(PACKAGE)-$(VERSION)/po/project.conf \ $(PACKAGE)-$(VERSION)/src/callbacks.c \ $(PACKAGE)-$(VERSION)/src/common.c \ $(PACKAGE)-$(VERSION)/src/key.c \ @@ -49,6 +54,7 @@ dist: $(PACKAGE)-$(VERSION)/COPYING \ $(PACKAGE)-$(VERSION)/Makefile \ $(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..4ff57f5 --- /dev/null +++ b/config.sh @@ -0,0 +1,5 @@ +PACKAGE="Keyboard" +VERSION="0.2.0" + +PREFIX="/usr/local" +LIBDIR="${PREFIX}/lib" diff --git a/po/.cvsignore b/po/.cvsignore new file mode 100644 index 0000000..4f01d45 --- /dev/null +++ b/po/.cvsignore @@ -0,0 +1,2 @@ +Keyboard.pot +fr.mo diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..72adfa3 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,30 @@ +TARGETS = Keyboard.pot fr.mo +PREFIX = /usr/local +DESTDIR = +RM ?= rm -f +LN ?= ln -f +MKDIR ?= mkdir -p +INSTALL ?= install + + +all: $(TARGETS) + +Keyboard.pot: POTFILES + ./gettext.sh -P "$(PREFIX)" -- "Keyboard.pot" + +fr.mo: Keyboard.pot fr.po + ./gettext.sh -P "$(PREFIX)" -- "fr.mo" + +clean: + $(RM) -- $(Keyboard.pot_OBJS) $(fr.mo_OBJS) + +distclean: clean + $(RM) -- $(TARGETS) + +install: $(TARGETS) + ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -i -- "fr.mo" + +uninstall: + ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -u -- "fr.mo" + +.PHONY: all clean distclean install uninstall diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 0000000..96123fe --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,2 @@ +../src/keyboard.c +../src/main.c diff --git a/po/fr.po b/po/fr.po new file mode 100644 index 0000000..7630ed2 --- /dev/null +++ b/po/fr.po @@ -0,0 +1,45 @@ +# $Id$ +# Copyright (c) 2012 Pierre Pronchery +# This file is distributed under the same license as the Keyboard package. +# Pierre Pronchery , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: Keyboard 0.2.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-05-20 14:38+0200\n" +"PO-Revision-Date: 2012-05-20 14:32+0200\n" +"Last-Translator: Pierre Pronchery \n" +"Language-Team: French\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" + +#: ../src/keyboard.c:97 +msgid "_Close" +msgstr "_Fermer" + +#: ../src/keyboard.c:105 ../src/keyboard.c:107 +msgid "_About" +msgstr "À propos" + +#: ../src/keyboard.c:114 +msgid "_File" +msgstr "_Fichier" + +#: ../src/keyboard.c:115 +msgid "_Help" +msgstr "_Aide" + +#: ../src/keyboard.c:488 +msgid "Keyboard" +msgstr "Clavier" + +#: ../src/keyboard.c:592 +msgid "Virtual keyboard for the DeforaOS desktop" +msgstr "Clavier virtuel pour l'environnement DeforaOS" + +#: ../src/main.c:46 +msgid "Usage: keyboard [-d|-p|-w|-x][-f font][-m monitor]\n" +msgstr "Usage: keyboard [-d|-p|-w|-x][-f police][-m moniteur]\n" diff --git a/po/gettext.sh b/po/gettext.sh new file mode 100755 index 0000000..2e90b3a --- /dev/null +++ b/po/gettext.sh @@ -0,0 +1,160 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2011 Pierre Pronchery +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +#variables +PREFIX="/usr/local" +. "../config.sh" +DEBUG="_debug" +INSTALL="install -m 0644" +LOCALEDIR="$PREFIX/share/locale" +MKDIR="mkdir -p" +MSGFMT="msgfmt" +MSGINIT="msginit" +MSGMERGE="msgmerge" +RM="rm -f" +POTFILES="POTFILES" +XGETTEXT="xgettext --force-po" + + +#functions +#debug +_debug() +{ + echo $@ + $@ +} + + +#usage +_usage() +{ + echo "Usage: gettext.sh [-i|-u][-P prefix] " 1>&2 + return 1 +} + + +#gettext_mo +_gettext_mo() +{ + package="$1" + lang="$2" + + _gettext_po "$package" "$lang" || return 1 + $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 + else + $DEBUG $MSGINIT -l "$lang" -o "$lang.po" -i "$package.pot" \ + || return 1 + fi +} + + +#gettext_pot +_gettext_pot() +{ + package="$1" + + $DEBUG $XGETTEXT -d "$package" -o "$package.pot" --keyword="_" \ + --keyword="N_" -f "$POTFILES" || return 1 +} + + +#main +install=0 +uninstall=0 +while getopts iuP: name; do + case "$name" in + i) + uninstall=0 + install=1 + ;; + u) + install=0 + uninstall=1 + ;; + P) + PREFIX="$2" + ;; + ?) + _usage + exit $? + ;; + esac +done +shift $(($OPTIND - 1)) +if [ $# -eq 0 ]; then + _usage + exit $? +fi + +LOCALEDIR="$PREFIX/share/locale" +while [ $# -gt 0 ]; do + target="$1" + lang="${target%%.mo}" + lang="${lang%%.po}" + shift + + #uninstall + if [ "$uninstall" -eq 1 ]; then + $DEBUG $RM "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \ + || exit 2 + continue + fi + + #create + case "$target" in + *.mo) + _gettext_mo "$PACKAGE" "$lang" || exit 2 + ;; + *.po) + _gettext_po "$PACKAGE" "$lang" || exit 2 + ;; + *.pot) + _gettext_pot "${target%%.pot}" || exit 2 + ;; + *) + exit 2 + ;; + esac + + #install + if [ "$install" -eq 1 ]; then + $DEBUG $MKDIR "$LOCALEDIR/$lang/LC_MESSAGES" || exit 2 + $DEBUG $INSTALL "$target" \ + "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \ + || exit 2 + fi +done diff --git a/po/project.conf b/po/project.conf new file mode 100644 index 0000000..c501670 --- /dev/null +++ b/po/project.conf @@ -0,0 +1,13 @@ +targets=Keyboard.pot,fr.mo +dist=Makefile,gettext.sh,POTFILES,fr.po + +[Keyboard.pot] +type=script +script=./gettext.sh +depends=POTFILES + +[fr.mo] +type=script +script=./gettext.sh +install= +depends=Keyboard.pot,fr.po diff --git a/project.conf b/project.conf index f2fb86c..2e28cb9 100644 --- a/project.conf +++ b/project.conf @@ -1,6 +1,6 @@ package=Keyboard version=0.2.0 -subdirs=data,include,src,tools -config=h -dist=COPYING,Makefile,config.h +subdirs=data,include,po,src,tools +config=h,sh +dist=COPYING,Makefile,config.h,config.sh diff --git a/src/keyboard.c b/src/keyboard.c index 087d825..9044c41 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -23,6 +23,7 @@ static char const _license[] = #include #include #include +#include #include #include #include @@ -34,6 +35,8 @@ static char const _license[] = #include "layout.h" #include "keyboard.h" #include "../config.h" +#define _(string) gettext(string) +#define N_(string) (string) /* Keyboard */ @@ -91,7 +94,7 @@ static char const * _authors[] = static const DesktopMenu _keyboard_menu_file[] = { - { "_Close", G_CALLBACK(on_file_close), GTK_STOCK_CLOSE, + { N_("_Close"), G_CALLBACK(on_file_close), GTK_STOCK_CLOSE, GDK_CONTROL_MASK, GDK_KEY_W }, { NULL, NULL, NULL, 0, 0 } }; @@ -99,17 +102,17 @@ static const DesktopMenu _keyboard_menu_file[] = static const DesktopMenu _keyboard_menu_help[] = { #if GTK_CHECK_VERSION(2, 6, 0) - { "_About", G_CALLBACK(on_help_about), GTK_STOCK_ABOUT, 0, 0 }, + { N_("_About"), G_CALLBACK(on_help_about), GTK_STOCK_ABOUT, 0, 0 }, #else - { "_About", G_CALLBACK(on_help_about), NULL, 0, 0 }, + { N_("_About"), G_CALLBACK(on_help_about), NULL, 0, 0 }, #endif { NULL, NULL, NULL, 0, 0 } }; static const DesktopMenubar _keyboard_menubar[] = { - { "_File", _keyboard_menu_file }, - { "_Help", _keyboard_menu_help }, + { N_("_File"), _keyboard_menu_file }, + { N_("_Help"), _keyboard_menu_help }, { NULL, NULL } }; @@ -482,7 +485,7 @@ static void _new_mode_windowed(Keyboard * keyboard) gtk_window_set_icon_name(GTK_WINDOW(keyboard->window), "input-keyboard"); #endif - gtk_window_set_title(GTK_WINDOW(keyboard->window), "Keyboard"); + gtk_window_set_title(GTK_WINDOW(keyboard->window), _("Keyboard")); g_signal_connect_swapped(G_OBJECT(keyboard->window), "delete-event", G_CALLBACK(on_keyboard_delete_event), keyboard); } @@ -586,7 +589,7 @@ void keyboard_show_about(Keyboard * keyboard) GTK_WINDOW(keyboard->window)); desktop_about_dialog_set_authors(keyboard->ab_window, _authors); desktop_about_dialog_set_comments(keyboard->ab_window, - "Virtual keyboard for the DeforaOS desktop"); + _("Virtual keyboard for the DeforaOS desktop")); desktop_about_dialog_set_copyright(keyboard->ab_window, _copyright); desktop_about_dialog_set_logo_icon_name(keyboard->ab_window, "input-keyboard"); diff --git a/src/main.c b/src/main.c index 461cc88..d4f1cc8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2010 Pierre Pronchery */ +/* Copyright (c) 2010-2012 Pierre Pronchery */ /* This file is part of DeforaOS Desktop Keyboard */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +19,24 @@ #include #include #include +#include +#include #include #include "keyboard.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 /* private */ @@ -28,7 +44,8 @@ /* usage */ static int _usage(void) { - fputs("Usage: keyboard [-d|-p|-w|-x][-f font][-m monitor]\n", stderr); + fputs(_("Usage: keyboard [-d|-p|-w|-x][-f font][-m monitor]\n"), + stderr); return 1; } @@ -43,6 +60,9 @@ int main(int argc, char * argv[]) KeyboardPrefs prefs; char * p; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); memset(&prefs, 0, sizeof(prefs)); gtk_init(&argc, &argv); while((o = getopt(argc, argv, "df:m:pwx")) != -1)