From 22ef6788de2a72fab830e6790884846d17f5d0bf Mon Sep 17 00:00:00 2001 From: SET Date: Sun, 16 Oct 2022 15:42:36 +0200 Subject: [PATCH] Add localization resources. --- .gitignore | 2 + Resources/Lokalize/0_getstrings.sh | 19 +++++ Resources/Lokalize/2_makemo.sh | 16 ++++ Resources/Lokalize/fr/saf7.po | 129 +++++++++++++++++++++++++++++ Resources/Lokalize/index.lokalize | 5 ++ SAF.cpp | 16 ++-- globals.h | 4 + main.cpp | 41 ++++----- 8 files changed, 205 insertions(+), 27 deletions(-) create mode 100755 Resources/Lokalize/0_getstrings.sh create mode 100755 Resources/Lokalize/2_makemo.sh create mode 100644 Resources/Lokalize/fr/saf7.po create mode 100644 Resources/Lokalize/index.lokalize diff --git a/.gitignore b/.gitignore index 098d45b..fa85398 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/ .kdev4 saf7.kdev4 +Resources/Lokalize/main.lqa +Resources/Lokalize/*/saf7.mo diff --git a/Resources/Lokalize/0_getstrings.sh b/Resources/Lokalize/0_getstrings.sh new file mode 100755 index 0000000..1c52a59 --- /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=saf7 +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..25433a2 --- /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=saf7 +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/saf7.po b/Resources/Lokalize/fr/saf7.po new file mode 100644 index 0000000..c069b62 --- /dev/null +++ b/Resources/Lokalize/fr/saf7.po @@ -0,0 +1,129 @@ +# 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 12:34+0200\n" +"PO-Revision-Date: 2022-10-16 12:55+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" + +#: ../../SAF.cpp:58 +msgid "Connected (" +msgstr "Connecté (" + +#: ../../SAF.cpp:65 +msgid "Disconnected (" +msgstr "Déconnecté (" + +#: ../../SAF.cpp:114 +msgid "Cannot initiate a connection. Check network, server, or parameters." +msgstr "" +"Ne peut initialiser une connexion. Vérifiez le réseau, le serveur ou les" +" paramètres." + +#: ../../SAF.cpp:119 +msgid "Try " +msgstr "Essai" + +#: ../../SAF.cpp:120 +msgid " : Waiting " +msgstr " : Attente" + +#: ../../SAF.cpp:121 +msgid " before connecting..." +msgstr " avant reconnexion" + +#: ../../SAF.cpp:127 +msgid "Giving up." +msgstr "Abandon." + +#: ../../main.cpp:68 +msgid "Signaled to exit." +msgstr "Signal d'arrêt." + +#: ../../main.cpp:79 +msgid "Full JID without resource" +msgstr "JID complet sans la partie 'resource'" + +#: ../../main.cpp:80 +msgid "Password" +msgstr "Mot de passe" + +#: ../../main.cpp:81 +msgid "Resource (optional)" +msgstr "Resource (optionnel)" + +#: ../../main.cpp:82 +msgid "Server (optional)" +msgstr "Serveur (optionnel)" + +#: ../../main.cpp:83 +msgid "Port (optional), default = 5222" +msgstr "Port (optionnel), par défaut : 5222" + +#: ../../main.cpp:84 +msgid "" +"Number of times to try to connect to server (optional), default = 0 (for " +"ever)" +msgstr "" +"Nombre de tentative de reconnexion au serveur (optionnel), par défaut : 0" +" (tentatives permanentes)" + +#: ../../main.cpp:85 +msgid "" +"Number of seconds between each connection attempt (optional), default = 30" +msgstr "Délai entre les tentatives de connexion (optionnel), par défaut : 30" + +#: ../../main.cpp:86 +msgid "" +"Number of seconds between each whitespace ping to the server (optional), " +"default = 0 (never), at least 55" +msgstr "" +"Délai entre les pings de maintien de connexion au serveur (optionnel), par" +" défaut : 0 (jamais), au moins 55" + +#: ../../main.cpp:87 +msgid "Bus name tag (optional), default=default" +msgstr "Étiquette du bus (optionnel), défaut : default" + +#: ../../main.cpp:88 +msgid "" +"Use specified configuration file (optional), else, pass all parameters on " +"the command line" +msgstr "" +"Utiliser un fichier de configuration (optionnel), ou fournir tous les" +" paramètres à la ligne de commande" + +#: ../../main.cpp:89 +msgid "Show messages (optional). Command line only." +msgstr "Sortie verbeuse (optionnel). Ligne de commande uniquement." + +#: ../../main.cpp:115 +msgid "Failure with file : " +msgstr "Échec avec le fichier :" + +#: ../../main.cpp:124 ../../main.cpp:130 +msgid "Error : " +msgstr "Erreur :" + +#: ../../main.cpp:136 +msgid "jid missing." +msgstr "jid manquant." + +#: ../../main.cpp:141 +msgid "password missing." +msgstr "Mot de passe manquant." + +#: ../../main.cpp:146 +msgid "wsping must be at least 55 seconds." +msgstr "wsping doit être au moins 55 secondes." diff --git a/Resources/Lokalize/index.lokalize b/Resources/Lokalize/index.lokalize new file mode 100644 index 0000000..31a6f8d --- /dev/null +++ b/Resources/Lokalize/index.lokalize @@ -0,0 +1,5 @@ +[General] +LangCode=fr_FR +MailingList= +ProjectID=saf7-Lokalize +TargetLangCode=fr_FR diff --git a/SAF.cpp b/SAF.cpp index f6f1958..d9006e5 100644 --- a/SAF.cpp +++ b/SAF.cpp @@ -55,14 +55,14 @@ void SAFConnListener::onConnect() m_lastError = ConnectionError::ConnNoError; m_connector->ResetCounter(); if (g_verbose) - cout << "Connected (" << m_client->jid().bare() << ")." << endl; + cout << _("Connected (") << m_client->jid().bare() << ")." << endl; } void SAFConnListener::onDisconnect(ConnectionError e) { m_lastError = e; if (g_verbose) - cout << "Disconnected (" << m_client->jid().bare() << ")." << endl; + cout << _("Disconnected (") << m_client->jid().bare() << ")." << endl; if (e == ConnNoError || e == ConnUserDisconnected) return; cout << ConnErrorMap[e] << endl; } @@ -111,20 +111,20 @@ void Connector::DoConnect() */ && m_saf->GetLastError() != ConnectionError::ConnConnectionRefused) { - cout << "Cannot initiate a connection." - " Check network, server, or parameters." << endl; + cout << _("Cannot initiate a connection." + " Check network, server, or parameters.") << endl; break; } if (g_verbose) - cout << "Try " << m_count - << " : Waiting " << m_delay << " seconds" - << " before connecting..." << endl; + cout << _("Try ") << m_count + << _(" : Waiting ") << m_delay << " seconds" + << _(" before connecting...") << endl; sleep(m_delay); m_count++; if (m_retry > 0 && m_count == m_retry) { if (g_verbose) - cout << "Giving up." << endl; + cout << _("Giving up.") << endl; break; } } diff --git a/globals.h b/globals.h index a2c6f4f..fb018d6 100644 --- a/globals.h +++ b/globals.h @@ -10,9 +10,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_ "saf7" // Send and forget #define _APP_DESCRIPTION_ "Send and forget an XMPP message" #define _VERSION_ "5" diff --git a/main.cpp b/main.cpp index e36ac54..403d58b 100644 --- a/main.cpp +++ b/main.cpp @@ -65,7 +65,7 @@ void signalhandler(int sn) delete g_client; delete g_saf; if (g_verbose) - cout << "Signaled to exit." << endl; + cout << _("Signaled to exit.") << endl; exit(0); } @@ -76,17 +76,17 @@ bool GetAndValidateParams(int argc, char** argv) po::options_description desc(_ABOUT_); desc.add_options() ("help,h", "Print help messages") - ("jid,j", po::value(&g_jid), "Full JID without resource") - ("password,w", po::value(&g_password), "Password") - ("resource,r", po::value(&g_resource), "Resource (optional)") - ("server,s", po::value(&g_server), "Server (optional)") - ("port,p", po::value(&g_port), "Port (optional), default = 5222") - ("retry,y", po::value(&g_retry), "Number of times to try to connect to server (optional), default = 0 (for ever)") - ("delay,d", po::value(&g_delay), "Number of seconds between each connection attempt (optional), default = 30") - ("wsping,g", po::value(&g_wsping), "Number of seconds between each whitespace ping to the server (optional), default = 0 (never), at least 55") - ("bustag,t", po::value(&g_tag), "Bus name tag (optional), default=default") - ("config,c", po::value(&g_config), "Use specified configuration file (optional), else, pass all parameters on the command line") - ("verbose,v", "Show messages (optional). Command line only."); + ("jid,j", po::value(&g_jid), _("Full JID without resource")) + ("password,w", po::value(&g_password), _("Password")) + ("resource,r", po::value(&g_resource), _("Resource (optional)")) + ("server,s", po::value(&g_server), _("Server (optional)")) + ("port,p", po::value(&g_port), _("Port (optional), default = 5222")) + ("retry,y", po::value(&g_retry), _("Number of times to try to connect to server (optional), default = 0 (for ever)")) + ("delay,d", po::value(&g_delay), _("Number of seconds between each connection attempt (optional), default = 30")) + ("wsping,g", po::value(&g_wsping), _("Number of seconds between each whitespace ping to the server (optional), default = 0 (never), at least 55")) + ("bustag,t", po::value(&g_tag), _("Bus name tag (optional), default=default")) + ("config,c", po::value(&g_config), _("Use specified configuration file (optional), else, pass all parameters on the command line")) + ("verbose,v", _("Show messages (optional). Command line only.")); po::variables_map vm; po::variables_map vmc; @@ -112,7 +112,7 @@ bool GetAndValidateParams(int argc, char** argv) ifstream f(g_config); if (f.fail()) { - cerr << "Failure with file : " << g_config << endl; + cerr << _("Failure with file : ") << g_config << endl; return 0; } po::store(po::parse_config_file(f, desc), vmc); @@ -121,29 +121,29 @@ bool GetAndValidateParams(int argc, char** argv) } catch (po::error& eb) { - cerr << "Error : " << eb.what() << endl; + cerr << _("Error : ") << eb.what() << endl; return 0; } } catch (exception& e) { - cerr << "Error : " << e.what() << endl; + cerr << _("Error : ") << e.what() << endl; return 0; } if (g_jid.empty()) { - cout << "jid missing." << endl; + cout << _("jid missing.") << endl; return 0; } if (g_password.empty()) { - cout << "password missing." << endl; + cout << _("password missing.") << endl; return 0; } if (g_wsping > 0 && g_wsping < 55 ) { - cout << "wsping must be at least 55 seconds." << endl; + cout << _("wsping must be at least 55 seconds.") << endl; return 0; } return true; @@ -167,7 +167,10 @@ DBusSafAdaptor* StartDBusAdaptor(Connector * connector, SAFConnListener * saf) int main(int argc, char** argv) { - + setlocale (LC_ALL, ""); + bindtextdomain (_APPNAME_, "/usr/local/share/locale"); // containing fr/LC_MESSAGES/ + textdomain (_APPNAME_); + if (!GetAndValidateParams(argc, argv)) return 0;