>From b33dce3931cb6be8018dc03daaab69df8de79be0 Mon Sep 17 00:00:00 2001
From: Jiri Moskovcak <jmoskovc@redhat.com>
Date: Mon, 4 Apr 2011 21:52:30 +0200
Subject: [PATCH] make event xml description translatable

---
 po/POTFILES.in                           |   10 +++-
 src/lib/event_xml_parser.c               |   73 +++++++++++++++++++++++++++--
 src/plugins/Makefile.am                  |   14 +++++-
 src/plugins/analyze_LocalGDB.xml         |    5 --
 src/plugins/analyze_LocalGDB.xml.in      |    5 ++
 src/plugins/analyze_RetraceServer.xml    |   13 -----
 src/plugins/analyze_RetraceServer.xml.in |   13 +++++
 src/plugins/report_Bugzilla.xml          |   28 -----------
 src/plugins/report_Bugzilla.xml.in       |   28 +++++++++++
 src/plugins/report_Kerneloops.xml        |   13 -----
 src/plugins/report_Kerneloops.xml.in     |   13 +++++
 src/plugins/report_Mailx.xml             |   28 -----------
 src/plugins/report_Mailx.xml.in          |   28 +++++++++++
 src/plugins/report_RHTSupport.xml        |   28 -----------
 src/plugins/report_RHTSupport.xml.in     |   28 +++++++++++
 15 files changed, 204 insertions(+), 123 deletions(-)
 delete mode 100644 src/plugins/analyze_LocalGDB.xml
 create mode 100644 src/plugins/analyze_LocalGDB.xml.in
 delete mode 100644 src/plugins/analyze_RetraceServer.xml
 create mode 100644 src/plugins/analyze_RetraceServer.xml.in
 delete mode 100644 src/plugins/report_Bugzilla.xml
 create mode 100644 src/plugins/report_Bugzilla.xml.in
 delete mode 100644 src/plugins/report_Kerneloops.xml
 create mode 100644 src/plugins/report_Kerneloops.xml.in
 delete mode 100644 src/plugins/report_Mailx.xml
 create mode 100644 src/plugins/report_Mailx.xml.in
 delete mode 100644 src/plugins/report_RHTSupport.xml
 create mode 100644 src/plugins/report_RHTSupport.xml.in

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 64a8524..ff47172 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,8 +14,8 @@ src/daemon/Daemon.cpp
 src/daemon/MiddleWare.cpp
 src/daemon/Settings.cpp
 src/gtk-helpers/event_config_dialog.c
-src/gui-gtk/abrt-gtk.c
 src/gui-gtk/abrt.desktop.in
+src/gui-gtk/abrt-gtk.c
 src/gui-gtk/main.c
 src/gui-wizard-gtk/main.c
 src/gui-wizard-gtk/wizard.c
@@ -23,8 +23,8 @@ src/gui-wizard-gtk/wizard.glade
 src/lib/abrt_curl.c
 src/lib/event_config.c
 src/lib/parse_options.c
-src/plugins/abrt-action-analyze-c.c
 src/plugins/abrt-action-analyze-backtrace.c
+src/plugins/abrt-action-analyze-c.c
 src/plugins/abrt-action-analyze-oops.c
 src/plugins/abrt-action-analyze-python.c
 src/plugins/abrt-action-bugzilla.cpp
@@ -38,3 +38,9 @@ src/plugins/abrt-action-trim-files.c
 src/plugins/abrt-action-upload.c
 src/plugins/abrt-dump-oops.c
 src/plugins/abrt-retrace-client.c
+src/plugins/analyze_LocalGDB.xml.in
+src/plugins/analyze_RetraceServer.xml.in
+src/plugins/report_Bugzilla.xml.in
+src/plugins/report_Kerneloops.xml.in
+src/plugins/report_Mailx.xml.in
+src/plugins/report_RHTSupport.xml.in
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
index a6aa9a1..8bb8902 100644
--- a/src/lib/event_xml_parser.c
+++ b/src/lib/event_xml_parser.c
@@ -34,6 +34,9 @@ struct my_parse_data
     event_option_t *cur_option;
 };
 
+static char *elem_lang;
+static char *locale;
+
 static const char *const option_types[] =
 {
     "text",
@@ -43,6 +46,39 @@ static const char *const option_types[] =
     NULL
 };
 
+static char * get_element_lang(const gchar **att_names, const gchar **att_values)
+{
+    char * short_locale_end = strchr(locale, '_');
+    VERB2 log("locale: %s", locale);
+    int i;
+    for (i = 0; att_names[i] != NULL; ++i)
+    {
+        VERB2 log("attr: %s:%s", att_names[i], att_values[i]);
+        if (strcmp(att_names[i], "xml:lang") == 0)
+        {
+            if (strcmp(att_values[i], locale) == 0)
+            {
+                VERB2 log("found translation for: %s", locale);
+                return xstrdup(att_values[i]);
+            }
+
+            /* try to match shorter locale
+             * e.g: "cs" with cs_CZ
+            */
+            if (strncmp(att_values[i], locale, short_locale_end-locale) == 0)
+            {
+                VERB2 log("found translation for shortlocale: %s", locale);
+                return xstrndup(att_values[i], short_locale_end-locale);
+            }
+        }
+    }
+    /* if the element has no attribute then it's a default non-localized value */
+    if (i == 0)
+        return xstrdup("C");
+    /* if the element is in different language then the current locale */
+    return NULL;
+}
+
 static int cmp_event_option_name_with_string(gconstpointer a, gconstpointer b)
 {
     return strcmp(((event_option_t *)a)->name, (char *)b);
@@ -132,6 +168,15 @@ static void start_element(GMarkupParseContext *context,
             }
         }
     }
+    else if (strcmp(element_name, LABEL_ELEMENT) == 0)
+    {
+        elem_lang = get_element_lang(attribute_names, attribute_values);
+    }
+    else if (strcmp(element_name, DESCRIPTION_ELEMENT) == 0)
+    {
+        elem_lang = get_element_lang(attribute_names, attribute_values);
+    }
+
 }
 
 // Called for close tags </foo>
@@ -142,6 +187,12 @@ static void end_element(GMarkupParseContext *context,
 {
     struct my_parse_data *parse_data = user_data;
 
+    if (elem_lang != NULL)
+    {
+        free(elem_lang);
+        elem_lang = NULL;
+    }
+
     if (strcmp(element_name, OPTION_ELEMENT) == 0)
     {
         consume_cur_option(parse_data);
@@ -171,8 +222,16 @@ static void text(GMarkupParseContext *context,
         if (strcmp(inner_element, LABEL_ELEMENT) == 0)
         {
             VERB2 log("new label:'%s'", text_copy);
-            free(opt->label);
-            opt->label = text_copy;
+            /* set the value only if we found a value for the current locale (elem_lang != "C")
+             * OR
+             * the label is still NULL and we found the default "C" value
+            */
+            if (elem_lang != NULL && ((strcmp(elem_lang, "C") != 0)
+            || (opt->label == NULL && (strcmp(elem_lang, "C") == 0))))
+            {
+                free(opt->label);
+                opt->label = text_copy;
+            }
             return;
         }
         /*
@@ -227,8 +286,12 @@ static void text(GMarkupParseContext *context,
         if (strcmp(inner_element, DESCRIPTION_ELEMENT) == 0)
         {
             VERB2 log("event description:'%s'", text_copy);
-            free(ui->description);
-            ui->description = text_copy;
+            if (elem_lang != NULL && ((strcmp(elem_lang, "C") != 0)
+            || (ui->description == NULL && (strcmp(elem_lang, "C") == 0))))
+            {
+                free(ui->description);
+                ui->description = text_copy;
+            }
             return;
         }
     }
@@ -267,7 +330,7 @@ static void error(GMarkupParseContext *context,
 void load_event_description_from_file(event_config_t *event_config, const char* filename)
 {
     struct my_parse_data parse_data = { event_config, NULL };
-
+    locale = setlocale(LC_ALL, "");
     GMarkupParser parser;
     memset(&parser, 0, sizeof(parser)); /* just in case */
     parser.start_element = &start_element;
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 7468188..418b5a1 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -42,6 +42,8 @@ dist_events_DATA = \
     report_RHTSupport.xml \
     report_Kerneloops.xml
 
+@INTLTOOL_XML_RULE@
+
 eventsconfdir = $(EVENTS_CONF_DIR)
 
 dist_eventsconf_DATA = \
@@ -59,7 +61,17 @@ man_MANS = \
 
 PYTHON_FILES = abrt-action-install-debuginfo.py abrt-action-list-dsos.py
 
-EXTRA_DIST = $(man_MANS) $(PYTHON_FILES)
+EXTRA_DIST = \
+    $(man_MANS) \
+    $(PYTHON_FILES) \
+    report_Bugzilla.xml.in \
+    report_Bugzilla.conf \
+    report_Logger.conf \
+    analyze_LocalGDB.xml.in \
+    analyze_RetraceServer.xml.in \
+    report_Mailx.xml.in \
+    report_RHTSupport.xml.in \
+    report_Kerneloops.xml.in
 
 $(DESTDIR)/$(DEBUG_INFO_DIR):
 	$(mkdir_p) '$@'
diff --git a/src/plugins/analyze_LocalGDB.xml b/src/plugins/analyze_LocalGDB.xml
deleted file mode 100644
index cf6064f..0000000
--- a/src/plugins/analyze_LocalGDB.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Local GNU Debugger</name>
-    <description>Download debuginfo packages and generate backtrace locally using GDB</description>
-</event>
diff --git a/src/plugins/analyze_LocalGDB.xml.in b/src/plugins/analyze_LocalGDB.xml.in
new file mode 100644
index 0000000..54209e7
--- /dev/null
+++ b/src/plugins/analyze_LocalGDB.xml.in
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <_name>Local GNU Debugger</_name>
+    <_description>Download debuginfo packages and generate backtrace locally using GDB</_description>
+</event>
diff --git a/src/plugins/analyze_RetraceServer.xml b/src/plugins/analyze_RetraceServer.xml
deleted file mode 100644
index ee5e225..0000000
--- a/src/plugins/analyze_RetraceServer.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Retrace Server</name>
-    <description>Send core dump to remote retrace server for analysis</description>
-    <options>
-        <option type="text" name="RETRACE_SERVER_URL">
-           <label>Retrace server URL</label>
-           <default-value>retrace01.fedoraproject.org</default-value>
-           <allow-empty>no</allow-empty>
-           <description>Address of the retrace server</description>
-       </option>
-    </options>
-</event>
diff --git a/src/plugins/analyze_RetraceServer.xml.in b/src/plugins/analyze_RetraceServer.xml.in
new file mode 100644
index 0000000..b3c7da2
--- /dev/null
+++ b/src/plugins/analyze_RetraceServer.xml.in
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <name>Retrace Server</name>
+    <_description>Send core dump to remote retrace server for analysis</_description>
+    <options>
+        <option type="text" name="RETRACE_SERVER_URL">
+           <_label>Retrace server URL</_label>
+           <default-value>retrace01.fedoraproject.org</default-value>
+           <allow-empty>no</allow-empty>
+           <_description>Address of the retrace server</_description>
+       </option>
+    </options>
+</event>
diff --git a/src/plugins/report_Bugzilla.xml b/src/plugins/report_Bugzilla.xml
deleted file mode 100644
index 34a0544..0000000
--- a/src/plugins/report_Bugzilla.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Bugzilla</name>
-    <description>Report to Bugzilla bug tracker</description>
-    <options>
-        <option type="text" name="Bugzilla_BugzillaURL">
-            <label>Bugzilla URL</label>
-            <allow-empty>no</allow-empty>
-            <description>Address of Bugzilla server</description>
-            <default-value>https://bugzilla.redhat.com</default-value>
-        </option>
-        <option type="text" name="Bugzilla_Login">
-            <label>User name</label>
-            <allow-empty>no</allow-empty>
-            <description>Bugzilla account user name</description>
-        </option>
-        <option type="password" name="Bugzilla_Password">
-            <label>Password</label>
-            <allow-empty>no</allow-empty>
-            <description>Bugzilla account password</description>
-        </option>
-        <option type="bool" name="Bugzilla_SSLVerify">
-            <label>Verify SSL</label>
-            <description>Check SSL key validity</description>
-            <default-value>yes</default-value>
-        </option>
-    </options>
-</event>
diff --git a/src/plugins/report_Bugzilla.xml.in b/src/plugins/report_Bugzilla.xml.in
new file mode 100644
index 0000000..6c87ad9
--- /dev/null
+++ b/src/plugins/report_Bugzilla.xml.in
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <_name>Bugzilla</_name>
+    <_description>Report to Bugzilla bug tracker</_description>
+    <options>
+        <option type="text" name="Bugzilla_BugzillaURL">
+            <_label>Bugzilla URL</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Address of Bugzilla server</_description>
+            <default-value>https://bugzilla.redhat.com</default-value>
+        </option>
+        <option type="text" name="Bugzilla_Login">
+            <_label>User name</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Bugzilla account user name</_description>
+        </option>
+        <option type="password" name="Bugzilla_Password">
+            <_label>Password</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Bugzilla account password</_description>
+        </option>
+        <option type="bool" name="Bugzilla_SSLVerify">
+            <_label>Verify SSL</_label>
+            <_description>Check SSL key validity</_description>
+            <default-value>yes</default-value>
+        </option>
+    </options>
+</event>
diff --git a/src/plugins/report_Kerneloops.xml b/src/plugins/report_Kerneloops.xml
deleted file mode 100644
index bafe34d..0000000
--- a/src/plugins/report_Kerneloops.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Kerneloops.org</name>
-    <description>Send kernel problems to oops tracker</description>
-    <options>
-        <option type="text" name="KerneloopsReporter_SubmitURL">
-            <label>Kerneloops URL</label>
-            <allow-empty>no</allow-empty>
-            <description>Oops server url</description>
-            <default-value>http://submit.kerneloops.org/submitoops.php</default-value>
-        </option>
-    </options>
-</event>
diff --git a/src/plugins/report_Kerneloops.xml.in b/src/plugins/report_Kerneloops.xml.in
new file mode 100644
index 0000000..83ea50b
--- /dev/null
+++ b/src/plugins/report_Kerneloops.xml.in
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <_name>Kerneloops.org</_name>
+    <_description>Send kernel problems to oops tracker</_description>
+    <options>
+        <option type="text" name="KerneloopsReporter_SubmitURL">
+            <_label>Kerneloops URL</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Oops server url</_description>
+            <default-value>http://submit.kerneloops.org/submitoops.php</default-value>
+        </option>
+    </options>
+</event>
diff --git a/src/plugins/report_Mailx.xml b/src/plugins/report_Mailx.xml
deleted file mode 100644
index 6ef33d1..0000000
--- a/src/plugins/report_Mailx.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Mailx</name>
-    <description>Send via email</description>
-    <options>
-        <option type="text" name="Mailx_Subject">
-            <label>Subject</label>
-            <allow-empty>no</allow-empty>
-            <description>Message subject</description>
-            <default-value>[abrt] detected a crash</default-value>
-        </option>
-        <option type="text" name="Mailx_EmailFrom">
-            <label>Sender</label>
-            <allow-empty>no</allow-empty>
-            <description>Sender's email</description>
-        </option>
-        <option type="text" name="Mailx_EmailTo">
-            <label>Recipient</label>
-            <allow-empty>no</allow-empty>
-            <description>Recipient's email</description>
-        </option>
-        <option type="bool" name="Mailx_SendBinaryData">
-            <label>Send Binary Data</label>
-            <description>Send binary files like coredump</description>
-            <default-value>no</default-value>
-        </option>
-    </options>
-</event>
diff --git a/src/plugins/report_Mailx.xml.in b/src/plugins/report_Mailx.xml.in
new file mode 100644
index 0000000..7584af7
--- /dev/null
+++ b/src/plugins/report_Mailx.xml.in
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <_name>Mailx</_name>
+    <_description>Send via email</_description>
+    <options>
+        <option type="text" name="Mailx_Subject">
+            <_label>Subject</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Message subject</_description>
+            <default-value>[abrt] detected a crash</default-value>
+        </option>
+        <option type="text" name="Mailx_EmailFrom">
+            <_label>Sender</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Sender's email</_description>
+        </option>
+        <option type="text" name="Mailx_EmailTo">
+            <_label>Recipient</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Recipient's email</_description>
+        </option>
+        <option type="bool" name="Mailx_SendBinaryData">
+            <_label>Send Binary Data</_label>
+            <_description>Send binary files like coredump</_description>
+            <default-value>no</default-value>
+        </option>
+    </options>
+</event>
diff --git a/src/plugins/report_RHTSupport.xml b/src/plugins/report_RHTSupport.xml
deleted file mode 100644
index 9dd0a73..0000000
--- a/src/plugins/report_RHTSupport.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<event>
-    <name>Red Hat Customer Support</name>
-    <description>Report to Red Hat support</description>
-    <options>
-        <option type="text" name="RHTSupport_URL">
-            <label>RH Portal URL</label>
-            <allow-empty>no</allow-empty>
-            <description>Address of the Red Hat support portal</description>
-            <default-value>https://api.access.redhat.com/rs</default-value>
-        </option>
-        <option type="text" name="RHTSupport_Login">
-            <label>Username</label>
-            <description>Red Hat customer user name</description>
-            <allow-empty>no</allow-empty>
-        </option>
-        <option type="password" name="RHTSupport_Password">
-            <label>Password</label>
-            <description>Red Hat customer password</description>
-            <allow-empty>no</allow-empty>
-        </option>
-        <option type="bool" name="RHTSupport_SSLVerify">
-            <label>Verify SSL</label>
-            <description>Check SSL key validity</description>
-            <default-value>yes</default-value>
-        </option>
-    </options>
-</event>
diff --git a/src/plugins/report_RHTSupport.xml.in b/src/plugins/report_RHTSupport.xml.in
new file mode 100644
index 0000000..725be3a
--- /dev/null
+++ b/src/plugins/report_RHTSupport.xml.in
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<event>
+    <_name>Red Hat Customer Support</_name>
+    <_description>Report to Red Hat support</_description>
+    <options>
+        <option type="text" name="RHTSupport_URL">
+            <_label>RH Portal URL</_label>
+            <allow-empty>no</allow-empty>
+            <_description>Address of the Red Hat support portal</_description>
+            <default-value>https://api.access.redhat.com/rs</default-value>
+        </option>
+        <option type="text" name="RHTSupport_Login">
+            <_label>Username</_label>
+            <_description>Red Hat customer user name</_description>
+            <allow-empty>no</allow-empty>
+        </option>
+        <option type="password" name="RHTSupport_Password">
+            <_label>Password</_label>
+            <_description>Red Hat customer password</_description>
+            <allow-empty>no</allow-empty>
+        </option>
+        <option type="bool" name="RHTSupport_SSLVerify">
+            <_label>Verify SSL</_label>
+            <_description>Check SSL key validity</_description>
+            <default-value>yes</default-value>
+        </option>
+    </options>
+</event>
-- 
1.7.4.2

