From bc490523d157b48435de0e922841f20f47155bd0 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 18 Jan 2013 22:42:01 +0100 Subject: [PATCH] Began the French translation --- Makefile | 7 +- po/Makefile | 31 +++++++++ po/POTFILES | 2 + po/fr.po | 25 +++++++ po/gettext.sh | 169 ++++++++++++++++++++++++++++++++++++++++++++++++ po/project.conf | 13 ++++ project.conf | 4 +- src/camera.c | 17 +++-- src/main.c | 22 ++++++- 9 files changed, 278 insertions(+), 12 deletions(-) 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 5bc0a22..ecaa7ee 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = Camera VERSION = 0.0.0 -SUBDIRS = data src tools +SUBDIRS = data po src tools RM = rm -f LN = ln -f TAR = tar -czvf @@ -25,6 +25,11 @@ dist: $(PACKAGE)-$(VERSION)/data/camera.desktop \ $(PACKAGE)-$(VERSION)/data/gallery.desktop \ $(PACKAGE)-$(VERSION)/data/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/camera.c \ $(PACKAGE)-$(VERSION)/src/main.c \ $(PACKAGE)-$(VERSION)/src/Makefile \ diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..6df8365 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,31 @@ +TARGETS = Camera.pot fr.mo +PREFIX = /usr/local +DESTDIR = +RM = rm -f +LN = ln -f +MKDIR = mkdir -p +INSTALL = install + + +all: $(TARGETS) + +Camera.pot: POTFILES + ./gettext.sh -P "$(PREFIX)" -- "Camera.pot" + +fr.mo: Camera.pot fr.po + ./gettext.sh -P "$(PREFIX)" -- "fr.mo" + +clean: + $(RM) -- $(Camera.pot_OBJS) $(fr.mo_OBJS) + ./gettext.sh -c -P "$(PREFIX)" -- "fr.mo" + +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..63d705d --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,2 @@ +../src/camera.c +../src/main.c diff --git a/po/fr.po b/po/fr.po new file mode 100644 index 0000000..9877017 --- /dev/null +++ b/po/fr.po @@ -0,0 +1,25 @@ +# $Id$ +# Copyright (c) 2013 Pierre Pronchery +# This file is distributed under the same license as the Camera package. +# Pierre Pronchery , 2013. +# +msgid "" +msgstr "" +"Project-Id-Version: Camera 0.0.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-01-18 22:35+0100\n" +"PO-Revision-Date: 2013-01-18 22:31+0100\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/main.c:65 +msgid "" +"Usage: camera [-d device]\n" +" -d\tVideo device to open\n" +msgstr "" +"Usage: camera [-d périphérique]\n" +" -d\tPériphérique video à ouvrir\n" diff --git a/po/gettext.sh b/po/gettext.sh new file mode 100755 index 0000000..4286018 --- /dev/null +++ b/po/gettext.sh @@ -0,0 +1,169 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2010-2013 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" +LOCALEDIR="$PREFIX/share/locale" +POTFILES="POTFILES" +#executables +DEBUG="_debug" +INSTALL="install -m 0644" +MKDIR="mkdir -p" +MSGFMT="msgfmt" +MSGINIT="msginit" +MSGMERGE="msgmerge" +RM="rm -f" +XGETTEXT="xgettext --force-po" + + +#functions +#debug +_debug() +{ + echo "$@" 1>&2 + "$@" +} + + +#usage +_usage() +{ + echo "Usage: gettext.sh [-c|-i|-u][-P prefix] target..." 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 +clean=0 +install=0 +uninstall=0 +while getopts "ciuP:" name; do + case "$name" in + c) + clean=1 + ;; + 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 + + #clean + [ "$clean" -ne 0 ] && continue + + #uninstall + if [ "$uninstall" -eq 1 ]; then + $DEBUG $RM "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \ + || exit 2 + continue + fi + + #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 + 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 +done diff --git a/po/project.conf b/po/project.conf new file mode 100644 index 0000000..4f3ad12 --- /dev/null +++ b/po/project.conf @@ -0,0 +1,13 @@ +targets=Camera.pot,fr.mo +dist=Makefile,gettext.sh,POTFILES,fr.po + +[Camera.pot] +type=script +script=./gettext.sh +depends=POTFILES + +[fr.mo] +type=script +script=./gettext.sh +install= +depends=Camera.pot,fr.po diff --git a/project.conf b/project.conf index be995e6..89f1173 100644 --- a/project.conf +++ b/project.conf @@ -1,6 +1,6 @@ package=Camera version=0.0.0 -subdirs=data,src,tools -config=h +subdirs=data,po,src,tools +config=h,sh dist=Makefile,config.h diff --git a/src/camera.c b/src/camera.c index 54fdd24..3bf6c08 100644 --- a/src/camera.c +++ b/src/camera.c @@ -31,12 +31,15 @@ static char const _license[] = #endif #include #include +#include #include #include #include #include #include "camera.h" #include "../config.h" +#define _(string) gettext(string) +#define N_(string) (string) /* Camera */ @@ -345,11 +348,11 @@ static int _snapshot_dcim(Camera * camera, char const * homedir, char * path; if((path = g_build_filename(homedir, dcim, NULL)) == NULL) - return -_camera_error(camera, "Could not save picture", 1); + return -_camera_error(camera, _("Could not save picture"), 1); if(mkdir(path, 0777) != 0 && errno != EEXIST) { - error_set_code(1, "%s: %s: %s", "Could not save picture", path, - strerror(errno)); + error_set_code(1, "%s: %s: %s", _("Could not save picture"), + path, strerror(errno)); free(path); return -_camera_error(camera, error_get(), 1); } @@ -368,7 +371,7 @@ static char * _snapshot_path(Camera * camera, char const * homedir, if(gettimeofday(&tv, NULL) != 0 || gmtime_r(&tv.tv_sec, &tm) == NULL) { - error_set_code(1, "%s: %s", "Could not save picture", + error_set_code(1, "%s: %s", _("Could not save picture"), strerror(errno)); _camera_error(camera, error_get(), 1); return NULL; @@ -387,7 +390,7 @@ static char * _snapshot_path(Camera * camera, char const * homedir, g_free(filename); if(path == NULL) { - _camera_error(camera, "Could not save picture", 1); + _camera_error(camera, _("Could not save picture"), 1); return NULL; } #ifdef DEBUG @@ -411,12 +414,12 @@ static int _snapshot_save(Camera * camera, char const * path) GDK_COLORSPACE_RGB, FALSE, 8, pix->width, pix->height, pix->width * 3, NULL, NULL)) == NULL) - return -_camera_error(camera, "Could not save picture", 1); + return -_camera_error(camera, _("Could not save picture"), 1); res = gdk_pixbuf_save(pixbuf, path, "png", &error, NULL); g_object_unref(pixbuf); if(res != TRUE) { - error_set_code(1, "%s: %s", "Could not save picture", + error_set_code(1, "%s: %s", _("Could not save picture"), error->message); g_error_free(error); return -_camera_error(camera, error_get(), 1); diff --git a/src/main.c b/src/main.c index 553a5df..e235e80 100644 --- a/src/main.c +++ b/src/main.c @@ -17,10 +17,25 @@ #include #include +#include +#include #include #include #include "camera.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 */ @@ -47,8 +62,8 @@ static int _camera(char const * device) /* usage */ static int _usage(void) { - fputs("Usage: camera [-d device]\n" -" -d Video device to open\n", stderr); + fputs(_("Usage: camera [-d device]\n" +" -d Video device to open\n"), stderr); return 1; } @@ -61,6 +76,9 @@ int main(int argc, char * argv[]) int o; char const * device = NULL; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); gtk_init(&argc, &argv); while((o = getopt(argc, argv, "d:")) != -1) switch(o)