Blame SOURCES/0043-localization-fix-gettext.patch

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