From a38dd6fe21613ebbffa48f8a6c095573d0d4da82 Mon Sep 17 00:00:00 2001 From: SET Date: Sun, 16 Oct 2022 18:10:38 +0200 Subject: [PATCH] Add localization resources. --- .gitignore | 2 + Resources/Lokalize/0_getstrings.sh | 19 ++++++++ Resources/Lokalize/2_makemo.sh | 16 +++++++ Resources/Lokalize/fr/PMP7.po | 71 ++++++++++++++++++++++++++++++ Resources/Lokalize/index.lokalize | 5 +++ globals.h | 7 +++ main.cpp | 30 +++++++------ 7 files changed, 137 insertions(+), 13 deletions(-) create mode 100755 Resources/Lokalize/0_getstrings.sh create mode 100755 Resources/Lokalize/2_makemo.sh create mode 100644 Resources/Lokalize/fr/PMP7.po create mode 100644 Resources/Lokalize/index.lokalize diff --git a/.gitignore b/.gitignore index 23a6c39..ddae71d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/ .kdev4 PMP7.kdev4 +Resources/Lokalize/main.lqa +Resources/Lokalize/fr/PMP7.mo diff --git a/Resources/Lokalize/0_getstrings.sh b/Resources/Lokalize/0_getstrings.sh new file mode 100755 index 0000000..d9e9095 --- /dev/null +++ b/Resources/Lokalize/0_getstrings.sh @@ -0,0 +1,19 @@ +#!/bin/bash +if [ ! -x 0_getstrings.sh ] +then + echo "Wrong working directory. Please cd to the directory containing this script." + exit 0 +fi + +APPNAME=PMP7 +SRC=../../ +DOMAIN=fr +DEST=$DOMAIN/$APPNAME.po +[ ! -d $DOMAIN ] && mkdir $DOMAIN +[ -f $DEST ] && JOIN="-j" +[ -f $DEST ] && cp $DEST $DEST.bak-$(date +%F-%T) + +xgettext --keyword=_ -d $DOMAIN $JOIN -o $DEST --c++ --from-code=UTF-8 $(find $SRC -maxdepth 1 -type f -name "*.cpp") +#xgettext --keyword=_ -d $DOMAIN -j -o $DEST --c++ --from-code=UTF-8 $(find $SRC -maxdepth 1 -type f -name "*.h") + +exit 0 diff --git a/Resources/Lokalize/2_makemo.sh b/Resources/Lokalize/2_makemo.sh new file mode 100755 index 0000000..b6a6fb9 --- /dev/null +++ b/Resources/Lokalize/2_makemo.sh @@ -0,0 +1,16 @@ +#!/bin/bash +if [ ! -x 2_makemo.sh ] +then + echo "Wrong working directory. Please cd to the directory containing this script." + exit 0 +fi + +APPNAME=PMP7 +DOMAIN=fr + +msgfmt $DOMAIN/$APPNAME.po -o $DOMAIN/$APPNAME.mo + +# cp $DOMAIN/$APPNAME.mo /usr/local/share/locale/$DOMAIN/LC_MESSAGES/ + +exit 0 + diff --git a/Resources/Lokalize/fr/PMP7.po b/Resources/Lokalize/fr/PMP7.po new file mode 100644 index 0000000..47df679 --- /dev/null +++ b/Resources/Lokalize/fr/PMP7.po @@ -0,0 +1,71 @@ +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# +# Saleem EDAH-TALLY , 2022. +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-10-16 17:56+0200\n" +"PO-Revision-Date: 2022-10-16 18:05+0200\n" +"Last-Translator: Saleem EDAH-TALLY \n" +"Language-Team: French <>\n" +"Language: fr_FR\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" +"X-Generator: Lokalize 22.08.2\n" + +#: ../../main.cpp:33 +msgid "Application signaled to exit." +msgstr "Fin d'application signalée." + +#: ../../main.cpp:44 +msgid "Print help messages." +msgstr "Afficher ceci." + +#: ../../main.cpp:45 +msgid "Media player : vlc, dragonplayer, xmms2..." +msgstr "Lecteur de media : vlc, dragonplayer, xmms2..." + +#: ../../main.cpp:46 +msgid "Show some messages on stdout, namely, signaled pedal codes." +msgstr "" +"Afficher quelques messages, en particulier, les codes émis par les pédales." + +#: ../../main.cpp:47 +msgid "Pedal code for - default : 4, unsigned." +msgstr "Code du pédalier pour - défaut : 4, non signé." + +#: ../../main.cpp:48 +msgid "Pedal code for - default : 2, unsigned." +msgstr "Code du pédalier pour - défaut : 2, non signé." + +#: ../../main.cpp:49 +msgid "Pedal code for - default : 1, unsigned." +msgstr "Code du pédalier pour - défaut : 1, non signé." + +#: ../../main.cpp:50 +msgid "" +"Automatically rewind for n milliseconds when playback stops - default : " +"1500, unsigned." +msgstr "" +"Retour arrière automatique de n millisecondes à l'arrêt de la lecture -" +" défaut : 1500, non signé." + +#: ../../main.cpp:71 +msgid "" +"Declared pedal codes are inconsistent. A pedal code should identify a unique " +"action." +msgstr "" +"Les codes de pédaliers déclarés sont inconsistants. Un code de pédalier doit" +" déclencher une action unique." + +#: ../../main.cpp:81 ../../main.cpp:87 +msgid "Error : " +msgstr "Erreur : " + +#: ../../main.cpp:124 +msgid "Could not listen to pedal events." +msgstr "Ne peut écouter les pédaliers." diff --git a/Resources/Lokalize/index.lokalize b/Resources/Lokalize/index.lokalize new file mode 100644 index 0000000..8553bd3 --- /dev/null +++ b/Resources/Lokalize/index.lokalize @@ -0,0 +1,5 @@ +[General] +LangCode=fr_FR +MailingList= +ProjectID=PMP7-Lokalize +TargetLangCode=fr_FR diff --git a/globals.h b/globals.h index b5f98e5..1d4ce18 100644 --- a/globals.h +++ b/globals.h @@ -9,6 +9,13 @@ #ifndef GLOBALS_H #define GLOBALS_H +#include +#include +using namespace std; + +//https://www.labri.fr/perso/fleury/posts/programming/a-quick-gettext-tutorial.html +#define _(STRING) gettext(STRING) + #define _APPNAME_ "PMP7" // Pedal control for Media Player #define _APP_DESCRIPTION_ "Controls media playback by foot pedal" #define _VERSION_ "2" diff --git a/main.cpp b/main.cpp index 3d58c95..e249614 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,7 @@ uint g_autorewind = 1500; void signalhandler(int sn) { if (g_verbose) - cout << "Application signaled to exit." << endl; + cout << _("Application signaled to exit.") << endl; delete g_pod7Proxy; exit(0); } @@ -41,13 +41,13 @@ bool ManageParams(int argc, char** argv) { po::options_description desc(_ABOUT_); desc.add_options() - ("help,h", "Print help messages.") - ("backend,b", po::value(&g_backend), "Media player : vlc, dragonplayer, xmms2...") - ("verbose,v", "Show some messages on stdout, namely, signaled pedal codes.") - ("play,p", po::value(&g_play), "Pedal code for - default : 4, unsigned.") - ("fastforward,f", po::value(&g_fastforward), "Pedal code for - default : 2, unsigned.") - ("rewind,r", po::value(&g_play), "Pedal code for - default : 1, unsigned.") - ("autorewind,a", po::value(&g_autorewind), "Automatically rewind for n milliseconds when playback stops - default : 1500, unsigned."); + ("help,h", _("Print help messages.")) + ("backend,b", po::value(&g_backend), _("Media player : vlc, dragonplayer, xmms2...")) + ("verbose,v", _("Show some messages on stdout, namely, signaled pedal codes.")) + ("play,p", po::value(&g_play), _("Pedal code for - default : 4, unsigned.")) + ("fastforward,f", po::value(&g_fastforward), _("Pedal code for - default : 2, unsigned.")) + ("rewind,r", po::value(&g_play), _("Pedal code for - default : 1, unsigned.")) + ("autorewind,a", po::value(&g_autorewind), _("Automatically rewind for n milliseconds when playback stops - default : 1500, unsigned.")); po::variables_map vm; try @@ -68,7 +68,7 @@ bool ManageParams(int argc, char** argv) || g_rewind == g_fastforward || g_play == g_fastforward) { - cout << "Declared pedal codes are inconsistent. A pedal code should identify a unique action." << endl; + cout << _("Declared pedal codes are inconsistent. A pedal code should identify a unique action.") << endl; return false; } if (vm.count("verbose")) @@ -78,13 +78,13 @@ bool ManageParams(int argc, char** argv) } catch (po::error& eb) { - cerr << "Error : " << eb.what() << endl; + cerr << _("Error : ") << eb.what() << endl; return false; } } catch (exception& e) { - cerr << "Error : " << e.what() << endl; + cerr << _("Error : ") << e.what() << endl; return false; } return true; @@ -109,6 +109,10 @@ bool StartPOD7Proxy() int main(int argc, char** argv) { + setlocale (LC_ALL, ""); + bindtextdomain (_APPNAME_, "/usr/local/share/locale"); // containing fr/LC_MESSAGES/ + textdomain (_APPNAME_); + if (!ManageParams(argc, argv)) return 0; signal(SIGINT, signalhandler); @@ -117,7 +121,7 @@ int main(int argc, char** argv) DBus::default_dispatcher = &g_dispatcher; if (!StartPOD7Proxy()) { - cout << "Could not listen to pedal events." << endl; + cout << _("Could not listen to pedal events.") << endl; return 0; } @@ -130,4 +134,4 @@ int main(int argc, char** argv) /* dbusxx-introspect /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.vlc dbusxx-introspect /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.dragonplayer - */ \ No newline at end of file + */