[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: Added patch by AV from ML:
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: Added patch by AV from ML: |
Date: |
Sun, 01 Sep 2019 13:27:15 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 3cca0d1e3 Added patch by AV from ML:
3cca0d1e3 is described below
commit 3cca0d1e32fcc78707e8a8740c81048f7fc21f5c
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sun Sep 1 13:25:07 2019 +0200
Added patch by AV from ML:
Currently, gettext doesn't work for out-of-tree applications. This is
because GNUnet forcibly set the text domain to "GNUnet" (which
apparently is also incorrect), so applications can't be localized unless
their localizations are distributed in-tree by GNUnet itself.
The attached patch tries to fix this by adding two more fields to
GNUNET_OS_ProjectData: one field is the gettext domain of the
application. As the documentation says, if it's NULL gettext is
disabled so that applications can use their preferred localization
method without having gettext interfering; the other field is
essentially the locale directory, so applications can specify a
different path if they want to, instead of having GNUnet infer it for
them.
Because some GNUnet libraries also use gettext internally (the util lib
is a prominent example), gettext has to be initialized before the
application takes over. I placed such initialization in
`GNUNET_OS_init' and `GNUNET_OS_project_data_get' because those are two
functions which are very likely to be called (especially the second one,
since it's used in `GNUNET_PROGRAM_run2'.) If there is a better place
(or some places where this is not enough) I can change it and resubmit
it for review.
I also changed gnunet-ext to keep it consitent with the patch. In
particular, it adds a header which is required for a successful
compilation, so you might want to at least make that change.
Thank you,
A.V.
P.S. I'm still not subscribed to the list... yet.
---
src/include/gnunet_os_lib.h | 12 ++++++++++++
src/include/platform.h | 2 +-
src/util/os_installation.c | 26 ++++++++++++++++++++++++++
src/util/program.c | 21 +++++++++++++--------
4 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index d43711a99..b632ab262 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -276,6 +276,18 @@ struct GNUNET_OS_ProjectData
* Non-zero means this project is part of GNU.
*/
int is_gnu;
+
+ /**
+ * Gettext domain for localisation, e.g. the PACKAGE macro.
+ * Setting this field to NULL disables gettext.
+ */
+ char *gettext_domain;
+
+ /**
+ * Gettext directory, e.g. the LOCALEDIR macro.
+ * If this field is NULL, the path is automatically inferred.
+ */
+ char *gettext_path;
};
diff --git a/src/include/platform.h b/src/include/platform.h
index 4636ddd73..0e3144ee8 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -205,7 +205,7 @@
/**
* GNU gettext support macro.
*/
-#define _(String) dgettext("gnunet",String)
+#define _(String) dgettext(PACKAGE,String)
#define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
#else
#include "libintlemu.h"
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 9dcfa5ef1..f51bfd287 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -64,6 +64,9 @@ static const struct GNUNET_OS_ProjectData default_pd = {
.homepage = "http://www.gnu.org/s/gnunet/",
.config_file = "gnunet.conf",
.user_config_file = "~/.config/gnunet.conf",
+ .is_gnu = 1,
+ .gettext_domain = PACKAGE,
+ .gettext_path = NULL,
};
/**
@@ -72,6 +75,13 @@ static const struct GNUNET_OS_ProjectData default_pd = {
*/
static const struct GNUNET_OS_ProjectData *current_pd = &default_pd;
+/**
+ * Wether or not gettext has been initialized for the library.
+ * Note that the gettext initialization done within
+ * GNUNET_PROGRAM_run2 is for the specific application.
+ */
+static int gettextinit = 0;
+
/**
* Return default project data used by 'libgnunetutil' for GNUnet.
*/
@@ -88,6 +98,14 @@ GNUNET_OS_project_data_default (void)
const struct GNUNET_OS_ProjectData *
GNUNET_OS_project_data_get ()
{
+ if (0 == gettextinit)
+ {
+ char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
+ if (NULL != path)
+ BINDTEXTDOMAIN (PACKAGE, path);
+ GNUNET_free(path);
+ gettextinit = 1;
+ }
return current_pd;
}
@@ -100,6 +118,14 @@ GNUNET_OS_project_data_get ()
void
GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
{
+ if (0 == gettextinit)
+ {
+ char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
+ if (NULL != path)
+ BINDTEXTDOMAIN (PACKAGE, path);
+ GNUNET_free(path);
+ gettextinit = 1;
+ }
GNUNET_assert (NULL != pd);
current_pd = pd;
}
diff --git a/src/util/program.c b/src/util/program.c
index 1462a03a8..73beb8d57 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -200,14 +200,19 @@ GNUNET_PROGRAM_run2 (int argc,
cc.cfg = cfg = GNUNET_CONFIGURATION_create ();
/* prepare */
#if ENABLE_NLS
- setlocale (LC_ALL, "");
- path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
- if (NULL != path)
- {
- BINDTEXTDOMAIN ("GNUnet", path);
- GNUNET_free (path);
- }
- textdomain ("GNUnet");
+ if (NULL != pd->gettext_domain)
+ {
+ setlocale (LC_ALL, "");
+ path = (NULL == pd->gettext_path)
+ ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
+ : GNUNET_strdup (pd->gettext_path);
+ if (NULL != path)
+ {
+ BINDTEXTDOMAIN (pd->gettext_domain, path);
+ GNUNET_free (path);
+ }
+ textdomain (pd->gettext_domain);
+ }
#endif
cnt = 0;
while (NULL != options[cnt].name)
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: Added patch by AV from ML:,
gnunet <=