0c9110
From c01356b4cda271c96a8129f66e63904f4b75efd2 Mon Sep 17 00:00:00 2001
0c9110
From: Jakub Filak <jfilak@redhat.com>
0c9110
Date: Tue, 15 Apr 2014 17:40:13 +0200
0c9110
Subject: [LIBREPORT PATCH 43/93] localization: fix gettext
0c9110
0c9110
https://www.gnu.org/software/gettext/manual/html_node/Libraries.html
0c9110
0c9110
Resolves to rhbz#1087861
0c9110
0c9110
Signed-off-by: Jakub Filak <jfilak@redhat.com>
0c9110
---
0c9110
 src/client-python/__init__.py            |  5 ++---
0c9110
 src/gtk-helpers/ask_dialogs.c            |  2 ++
0c9110
 src/gtk-helpers/config_dialog.c          |  5 +++++
0c9110
 src/gtk-helpers/event_config_dialog.c    |  6 ++++++
0c9110
 src/gtk-helpers/secrets.c                |  8 ++++++++
0c9110
 src/gtk-helpers/workflow_config_dialog.c |  2 ++
0c9110
 src/include/internal_libreport.h         | 15 ++++++++++++++-
0c9110
 src/lib/Makefile.am                      |  6 +++++-
0c9110
 src/lib/abrt_sock.c                      |  2 ++
0c9110
 src/lib/client.c                         | 10 ++++------
0c9110
 src/lib/create_dump_dir.c                |  2 ++
0c9110
 src/lib/curl.c                           |  2 ++
0c9110
 src/lib/event_config.c                   |  4 ++++
0c9110
 src/lib/libreport_init.c                 | 28 ++++++++++++++++++++++++++++
0c9110
 src/lib/make_descr.c                     |  2 ++
0c9110
 src/lib/parse_options.c                  |  2 ++
0c9110
 src/lib/problem_data.c                   |  2 ++
0c9110
 src/lib/run_event.c                      |  2 ++
0c9110
 18 files changed, 94 insertions(+), 11 deletions(-)
0c9110
 create mode 100644 src/lib/libreport_init.c
0c9110
0c9110
diff --git a/src/client-python/__init__.py b/src/client-python/__init__.py
0c9110
index 53f5f92..8966f22 100644
0c9110
--- a/src/client-python/__init__.py
0c9110
+++ b/src/client-python/__init__.py
0c9110
@@ -30,11 +30,11 @@ from report import EXIT_CANCEL_BY_USER as RETURN_CANCEL_BY_USER
0c9110
 from report import EXIT_STOP_EVENT_RUN as RETURN_STOP_EVENT_RUN
0c9110
 
0c9110
 
0c9110
-GETTEXT_PROGNAME = "abrt"
0c9110
+GETTEXT_PROGNAME = "libreport"
0c9110
 import locale
0c9110
 import gettext
0c9110
 
0c9110
-_ = lambda x: gettext.lgettext(x)
0c9110
+_ = lambda x: gettext.ldgettext(GETTEXT_PROGNAME, x)
0c9110
 
0c9110
 def init_gettext():
0c9110
     try:
0c9110
@@ -48,7 +48,6 @@ def init_gettext():
0c9110
     except AttributeError:
0c9110
         pass
0c9110
     gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
0c9110
-    gettext.textdomain(GETTEXT_PROGNAME)
0c9110
 
0c9110
 init_gettext()
0c9110
 
0c9110
diff --git a/src/gtk-helpers/ask_dialogs.c b/src/gtk-helpers/ask_dialogs.c
0c9110
index a038126..d188dc5 100644
0c9110
--- a/src/gtk-helpers/ask_dialogs.c
0c9110
+++ b/src/gtk-helpers/ask_dialogs.c
0c9110
@@ -54,6 +54,8 @@ static int run_ask_yes_no_save_generic_result_dialog(ask_yes_no_dialog_flags fla
0c9110
                                                      const char *message,
0c9110
                                                      GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     const char *ask_result = get_user_setting(key);
0c9110
 
0c9110
     if (ask_result)
0c9110
diff --git a/src/gtk-helpers/config_dialog.c b/src/gtk-helpers/config_dialog.c
0c9110
index fb22561..c80dc56 100644
0c9110
--- a/src/gtk-helpers/config_dialog.c
0c9110
+++ b/src/gtk-helpers/config_dialog.c
0c9110
@@ -145,6 +145,8 @@ void dehydrate_config_dialog(GList *option_widgets)
0c9110
 
0c9110
 void add_item_to_config_liststore(gpointer cdialog, gpointer inf, gpointer user_data)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     GtkListStore *list_store = (GtkListStore *)user_data;
0c9110
     config_item_info_t *info = (config_item_info_t *)inf;
0c9110
 
0c9110
@@ -272,6 +274,7 @@ static void on_close_cb(GtkWidget *btn, gpointer config_list_w)
0c9110
 
0c9110
 GtkWindow *create_config_list_window(GHashTable *configs, GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
 
0c9110
     // config window
0c9110
     GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
0c9110
@@ -341,6 +344,8 @@ GtkWindow *create_config_list_window(GHashTable *configs, GtkWindow *parent)
0c9110
 
0c9110
 void show_config_list_dialog(GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     GHashTable *confs = g_hash_table_new_full(
0c9110
             /*hash_func*/ g_str_hash,
0c9110
             /*key_equal_func:*/ g_str_equal,
0c9110
diff --git a/src/gtk-helpers/event_config_dialog.c b/src/gtk-helpers/event_config_dialog.c
0c9110
index c8a251c..1ed5196 100644
0c9110
--- a/src/gtk-helpers/event_config_dialog.c
0c9110
+++ b/src/gtk-helpers/event_config_dialog.c
0c9110
@@ -191,6 +191,8 @@ static void add_option_to_table(gpointer data, gpointer user_data)
0c9110
 
0c9110
 config_dialog_t *create_event_config_dialog_content(event_config_t *event, GtkWidget *content)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     if (content == NULL)
0c9110
         content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
0c9110
 
0c9110
@@ -285,6 +287,8 @@ config_dialog_t *create_event_config_dialog_content(event_config_t *event, GtkWi
0c9110
 
0c9110
 config_dialog_t *create_event_config_dialog(const char *event_name, GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     event_config_t *event = get_event_config(event_name);
0c9110
 
0c9110
     if(!ec_is_configurable(event))
0c9110
@@ -340,6 +344,8 @@ GtkListStore *add_events_to_liststore(GHashTable *events)
0c9110
 
0c9110
 int show_event_config_dialog(const char *event_name, GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     event_config_t *event = get_event_config(event_name);
0c9110
 
0c9110
     GtkWindow *parent_window = parent ? parent : g_event_list_window;
0c9110
diff --git a/src/gtk-helpers/secrets.c b/src/gtk-helpers/secrets.c
0c9110
index 86c2208..fdc6616 100644
0c9110
--- a/src/gtk-helpers/secrets.c
0c9110
+++ b/src/gtk-helpers/secrets.c
0c9110
@@ -1493,6 +1493,8 @@ static void save_event_config(const char *event_name,
0c9110
 
0c9110
 bool is_event_config_user_storage_available()
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     if (g_state == SBS_INITIAL)
0c9110
         g_state = secrets_service_connect();
0c9110
 
0c9110
@@ -1507,6 +1509,8 @@ bool is_event_config_user_storage_available()
0c9110
  */
0c9110
 void load_single_event_config_data_from_user_storage(event_config_t *config)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     GHashTable *tmp = g_hash_table_new_full(
0c9110
                 /*hash_func*/ g_str_hash,
0c9110
                 /*key_equal_func:*/ g_str_equal,
0c9110
@@ -1529,6 +1533,8 @@ void load_single_event_config_data_from_user_storage(event_config_t *config)
0c9110
  */
0c9110
 void load_event_config_data_from_user_storage(GHashTable *event_config_list)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     if (is_event_config_user_storage_available())
0c9110
     {
0c9110
         bool dismissed = false;
0c9110
@@ -1589,6 +1595,8 @@ void save_event_config_data_to_user_storage(const char *event_name,
0c9110
                                             const event_config_t *event_config,
0c9110
                                             bool store_passwords)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     if (is_event_config_user_storage_available())
0c9110
         save_event_config(event_name, event_config->options, store_passwords);
0c9110
     else
0c9110
diff --git a/src/gtk-helpers/workflow_config_dialog.c b/src/gtk-helpers/workflow_config_dialog.c
0c9110
index fb312e3..7c399e4 100644
0c9110
--- a/src/gtk-helpers/workflow_config_dialog.c
0c9110
+++ b/src/gtk-helpers/workflow_config_dialog.c
0c9110
@@ -64,6 +64,8 @@ void save_data_from_worfklow_dialog(gpointer data, /* not needed */ const char *
0c9110
 
0c9110
 config_dialog_t *create_workflow_config_dialog(const char *workflow_name, GtkWindow *parent)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     workflow_t *workflow = get_workflow(workflow_name);
0c9110
     GList *events = wf_get_event_list(workflow);
0c9110
 
0c9110
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
0c9110
index e6d3150..f9670b0 100644
0c9110
--- a/src/include/internal_libreport.h
0c9110
+++ b/src/include/internal_libreport.h
0c9110
@@ -62,7 +62,7 @@
0c9110
 /* Must be after #include "config.h" */
0c9110
 #if ENABLE_NLS
0c9110
 # include <libintl.h>
0c9110
-# define _(S) gettext(S)
0c9110
+# define _(S) dgettext(PACKAGE, S)
0c9110
 #else
0c9110
 # define _(S) (S)
0c9110
 #endif
0c9110
@@ -925,6 +925,19 @@ enum {
0c9110
 #define log_problem_data libreport_log_problem_data
0c9110
 void log_problem_data(problem_data_t *problem_data, const char *pfx);
0c9110
 
0c9110
+extern int g_libreport_inited;
0c9110
+void libreport_init(void);
0c9110
+
0c9110
+#define INITIALIZE_LIBREPORT() \
0c9110
+    do \
0c9110
+    { \
0c9110
+        if (!g_libreport_inited) \
0c9110
+        { \
0c9110
+            g_libreport_inited = 1; \
0c9110
+            libreport_init(); \
0c9110
+        } \
0c9110
+    } \
0c9110
+    while (0)
0c9110
 
0c9110
 const char *abrt_init(char **argv);
0c9110
 #define export_abrt_envvars libreport_export_abrt_envvars
0c9110
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
0c9110
index ac173f6..d2ff675 100644
0c9110
--- a/src/lib/Makefile.am
0c9110
+++ b/src/lib/Makefile.am
0c9110
@@ -54,7 +54,9 @@ libreport_la_SOURCES = \
0c9110
     workflow.c \
0c9110
     workflow_xml_parser.c \
0c9110
     config_item_info.c \
0c9110
-    xml_parser.c
0c9110
+    xml_parser.c \
0c9110
+    libreport_init.c
0c9110
+
0c9110
 libreport_la_CPPFLAGS = \
0c9110
     -I$(srcdir)/../include \
0c9110
     -DLOCALSTATEDIR='"$(localstatedir)"' \
0c9110
@@ -145,6 +147,8 @@ libreport_web_la_LIBADD = \
0c9110
     $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) \
0c9110
     libreport.la
0c9110
 
0c9110
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
0c9110
+
0c9110
 $(DESTDIR)/$(DEBUG_DUMPS_DIR):
0c9110
 	$(mkdir_p) '$@'
0c9110
 # no need to chmod it here
0c9110
diff --git a/src/lib/abrt_sock.c b/src/lib/abrt_sock.c
0c9110
index 1526623..962ecc9 100644
0c9110
--- a/src/lib/abrt_sock.c
0c9110
+++ b/src/lib/abrt_sock.c
0c9110
@@ -136,6 +136,8 @@ int problem_data_send_to_abrt(problem_data_t* problem_data)
0c9110
 
0c9110
 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
 #if DUMP_DIR_OWNED_BY_USER == 0
0c9110
     /* Try to delete it ourselves */
0c9110
     struct dump_dir *dd = dd_opendir(dump_dir_name, DD_OPEN_READONLY);
0c9110
diff --git a/src/lib/client.c b/src/lib/client.c
0c9110
index 7761150..93b4876 100644
0c9110
--- a/src/lib/client.c
0c9110
+++ b/src/lib/client.c
0c9110
@@ -50,9 +50,8 @@ int set_echo(int enable)
0c9110
 
0c9110
 int ask_yes_no(const char *question)
0c9110
 {
0c9110
-#if ENABLE_NLS
0c9110
-    textdomain(PACKAGE);
0c9110
-#endif
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     const char *yes = _("y");
0c9110
     const char *no = _("N");
0c9110
 
0c9110
@@ -83,9 +82,8 @@ int ask_yes_no(const char *question)
0c9110
 
0c9110
 int ask_yes_no_yesforever(const char *key, const char *question)
0c9110
 {
0c9110
-#if ENABLE_NLS
0c9110
-    textdomain(PACKAGE);
0c9110
-#endif
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     const char *yes = _("y");
0c9110
     const char *no = _("N");
0c9110
     const char *forever = _("f");
0c9110
diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c
0c9110
index d48b099..4f67523 100644
0c9110
--- a/src/lib/create_dump_dir.c
0c9110
+++ b/src/lib/create_dump_dir.c
0c9110
@@ -32,6 +32,8 @@ static struct dump_dir *try_dd_create(const char *base_dir_name, const char *dir
0c9110
 
0c9110
 struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     char *type = problem_data_get_content_or_NULL(problem_data, FILENAME_ANALYZER);
0c9110
 
0c9110
     if (!type)
0c9110
diff --git a/src/lib/curl.c b/src/lib/curl.c
0c9110
index 662a2cf..5ca18dd 100644
0c9110
--- a/src/lib/curl.c
0c9110
+++ b/src/lib/curl.c
0c9110
@@ -301,6 +301,8 @@ post(post_state_t *state,
0c9110
                 const char *data,
0c9110
                 off_t data_size)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     CURLcode curl_err;
0c9110
     long response_code;
0c9110
     post_state_t localstate;
0c9110
diff --git a/src/lib/event_config.c b/src/lib/event_config.c
0c9110
index b25517d..30b94d3 100644
0c9110
--- a/src/lib/event_config.c
0c9110
+++ b/src/lib/event_config.c
0c9110
@@ -395,6 +395,8 @@ static char *validate_event_option(event_option_t *opt)
0c9110
 
0c9110
 GHashTable *validate_event(const char *event_name)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     event_config_t *config = get_event_config(event_name);
0c9110
     if (!config)
0c9110
         return NULL;
0c9110
@@ -435,6 +437,8 @@ bool check_problem_rating_usability(const event_config_t *cfg,
0c9110
                                     char **description,
0c9110
                                     char **detail)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     char *tmp_desc = NULL;
0c9110
     char *tmp_detail = NULL;
0c9110
     bool result = true;
0c9110
diff --git a/src/lib/libreport_init.c b/src/lib/libreport_init.c
0c9110
new file mode 100644
0c9110
index 0000000..8b9c3f5
0c9110
--- /dev/null
0c9110
+++ b/src/lib/libreport_init.c
0c9110
@@ -0,0 +1,28 @@
0c9110
+/*
0c9110
+    Copyright (C) 2014  ABRT team
0c9110
+    Copyright (C) 2014  RedHat Inc
0c9110
+
0c9110
+    This program is free software; you can redistribute it and/or modify
0c9110
+    it under the terms of the GNU General Public License as published by
0c9110
+    the Free Software Foundation; either version 2 of the License, or
0c9110
+    (at your option) any later version.
0c9110
+
0c9110
+    This program is distributed in the hope that it will be useful,
0c9110
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
0c9110
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0c9110
+    GNU General Public License for more details.
0c9110
+
0c9110
+    You should have received a copy of the GNU General Public License along
0c9110
+    with this program; if not, write to the Free Software Foundation, Inc.,
0c9110
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0c9110
+*/
0c9110
+#include "internal_libreport.h"
0c9110
+
0c9110
+int g_libreport_inited;
0c9110
+
0c9110
+void libreport_init(void)
0c9110
+{
0c9110
+#if ENABLE_NLS
0c9110
+    bindtextdomain(PACKAGE, LOCALEDIR);
0c9110
+#endif
0c9110
+}
0c9110
diff --git a/src/lib/make_descr.c b/src/lib/make_descr.c
0c9110
index 660a7ac..d183ac1 100644
0c9110
--- a/src/lib/make_descr.c
0c9110
+++ b/src/lib/make_descr.c
0c9110
@@ -51,6 +51,8 @@ char *make_description_item_multiline(const char *name, const char *content)
0c9110
 char *make_description(problem_data_t *problem_data, char **names_to_skip,
0c9110
                        unsigned max_text_size, unsigned desc_flags)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     struct strbuf *buf_dsc = strbuf_new();
0c9110
 
0c9110
     const char *analyzer = problem_data_get_content_or_NULL(problem_data,
0c9110
diff --git a/src/lib/parse_options.c b/src/lib/parse_options.c
0c9110
index 3f079d2..b6bf312 100644
0c9110
--- a/src/lib/parse_options.c
0c9110
+++ b/src/lib/parse_options.c
0c9110
@@ -55,6 +55,8 @@ void export_abrt_envvars(int pfx)
0c9110
 
0c9110
 void show_usage_and_die(const char *usage, const struct options *opt)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     fputs(_("Usage: "), stderr);
0c9110
     while (*usage)
0c9110
     {
0c9110
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
0c9110
index 3b90b43..18d9541 100644
0c9110
--- a/src/lib/problem_data.c
0c9110
+++ b/src/lib/problem_data.c
0c9110
@@ -207,6 +207,8 @@ void problem_data_add_file(problem_data_t *pd, const char *name, const char *pat
0c9110
 
0c9110
 char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     struct problem_item *item = problem_data_get_item_or_NULL(problem_data, key);
0c9110
     if (!item)
0c9110
         error_msg_and_die(_("Essential element '%s' is missing, can't continue"), key);
0c9110
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
0c9110
index 5efc0c5..a56cf88 100644
0c9110
--- a/src/lib/run_event.c
0c9110
+++ b/src/lib/run_event.c
0c9110
@@ -756,6 +756,8 @@ static void run_event_stdio_error_and_die(const char *error_line, void *param)
0c9110
 
0c9110
 char *exit_status_as_string(const char *progname, int status)
0c9110
 {
0c9110
+    INITIALIZE_LIBREPORT();
0c9110
+
0c9110
     char *msg;
0c9110
     if (WIFSIGNALED(status))
0c9110
         msg = xasprintf(_("('%s' was killed by signal %u)\n"), progname, WTERMSIG(status));
0c9110
-- 
0c9110
1.8.3.1
0c9110