Hi,

Recently xgettext --kde was updated to recognize the difference between KDE
plain text (kde-format) and markup formats (kde-kuit-format), and msgfmt to
even validate markup. (Thanks again, Daiki!) But, to properly extract
messages from a KDE source, the user has to add many --keyword and --flag
options (20-40 each). This array of options can of course be documented for
verbatim copying, or tucked away inside the build system, nevertheless I
argued it made sense to automatically recognize default KDE keywords and
flags when --kde option was present. Now I attach an attempted patch to do
this.

I was mostly struggling with how to trigger addition of KDE keywords. In the
end I came up with activate_additional_keywords_kde function, but I'm not
sure if that is elegant enough.

-- 
Chusslove Illich (Часлав Илић)
diff --git a/NEWS b/NEWS
index ac3a634..3a01dba 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,9 @@ Version 0.19.5 - unreleased
   - C++ with KDE: xgettext and msgfmt can now recognize KUIT (KDE User
     Interface Text) markup.  See the documentation section "KUIT
     Format Strings" for more info.
+  - C++ with KDE: xgettext now recognizes all default KDE keywords.
+    This removes the need for a long list of --keyword and --flag
+    options to perform a reasonable extraction.
 
 * Bug fixes:
   - xgettext C++11 raw string recognition is now stricter and don't
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index a8e070e..3283a04 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,14 @@
+2015-05-08  Часлав Илић (Chusslove Illich)  <caslav.i...@gmx.net>
+
+	* x-c.c (init_flag_table_kde): New function.
+	(additional_keywords_kde): New variable.
+	(activate_additional_keywords_kde): New function.
+	(init_keywords): Optional addition of KDE-specific keywords.
+	* x-c.h (init_flag_table_kde): New function declaration.
+	(activate_additional_keywords_kde): New function declaration.
+	* xgettext.c (main): Invoke addition of KDE-specific keywords when
+	language is C++ with KDE.
+
 2015-03-20  Daiki Ueno  <u...@gnu.org>
 
 	kde-kuit: Use xmlns to avoid element name conflict
diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c
index e60dcad..d32cb6c 100644
--- a/gettext-tools/src/x-c.c
+++ b/gettext-tools/src/x-c.c
@@ -143,6 +143,14 @@ x_objc_keyword (const char *name)
   add_keyword (name, &objc_keywords);
 }
 
+static bool additional_keywords_kde;
+
+void
+activate_additional_keywords_kde ()
+{
+  additional_keywords_kde = true;
+}
+
 /* Finish initializing the keywords hash tables.
    Called after argument processing, before each file is processed.  */
 static void
@@ -166,6 +174,50 @@ init_keywords ()
       x_c_keyword ("dnpgettext:2c,3,4");
       x_c_keyword ("dcnpgettext:2c,3,4");
 
+      if (additional_keywords_kde)
+        {
+          x_c_keyword ("i18n:1");
+          x_c_keyword ("i18nc:1c,2");
+          x_c_keyword ("i18np:1,2");
+          x_c_keyword ("i18ncp:1c,2,3");
+          x_c_keyword ("i18nd:2");
+          x_c_keyword ("i18ndc:2c,3");
+          x_c_keyword ("i18ndp:2,3");
+          x_c_keyword ("i18ndcp:2c,3,4");
+          x_c_keyword ("ki18n:1");
+          x_c_keyword ("ki18nc:1c,2");
+          x_c_keyword ("ki18np:1,2");
+          x_c_keyword ("ki18ncp:1c,2,3");
+          x_c_keyword ("ki18nd:2");
+          x_c_keyword ("ki18ndc:2c,3");
+          x_c_keyword ("ki18ndp:2,3");
+          x_c_keyword ("ki18ndcp:2c,3,4");
+          x_c_keyword ("I18N_NOOP:1");
+          x_c_keyword ("I18NC_NOOP:1c,2");
+          x_c_keyword ("I18N_NOOP2:1c,2");
+          x_c_keyword ("I18N_NOOP2_NOSTRIP:1c,2");
+          x_c_keyword ("xi18n:1");
+          x_c_keyword ("xi18nc:1c,2");
+          x_c_keyword ("xi18np:1,2");
+          x_c_keyword ("xi18ncp:1c,2,3");
+          x_c_keyword ("xi18nd:2");
+          x_c_keyword ("xi18ndc:2c,3");
+          x_c_keyword ("xi18ndp:2,3");
+          x_c_keyword ("xi18ndcp:2c,3,4");
+          x_c_keyword ("kxi18n:1");
+          x_c_keyword ("kxi18nc:1c,2");
+          x_c_keyword ("kxi18np:1,2");
+          x_c_keyword ("kxi18ncp:1c,2,3");
+          x_c_keyword ("kxi18nd:2");
+          x_c_keyword ("kxi18ndc:2c,3");
+          x_c_keyword ("kxi18ndp:2,3");
+          x_c_keyword ("kxi18ndcp:2c,3,4");
+          x_c_keyword ("XI18N_NOOP:1");
+          x_c_keyword ("XI18NC_NOOP:1c,2");
+          x_c_keyword ("XI18N_NOOP2:1c,2");
+          x_c_keyword ("XI18N_NOOP2_NOSTRIP:1c,2");
+        }
+
       x_objc_keyword ("gettext");
       x_objc_keyword ("dgettext:2");
       x_objc_keyword ("dcgettext:2");
@@ -449,6 +501,50 @@ init_flag_table_gcc_internal ()
 #endif
 }
 
+void
+init_flag_table_kde ()
+{
+  xgettext_record_flag ("i18n:1:kde-format");
+  xgettext_record_flag ("i18nc:2:kde-format");
+  xgettext_record_flag ("i18np:1:kde-format");
+  xgettext_record_flag ("i18ncp:2:kde-format");
+  xgettext_record_flag ("i18nd:2:kde-format");
+  xgettext_record_flag ("i18ndc:3:kde-format");
+  xgettext_record_flag ("i18ndp:2:kde-format");
+  xgettext_record_flag ("i18ndcp:3:kde-format");
+  xgettext_record_flag ("ki18n:1:kde-format");
+  xgettext_record_flag ("ki18nc:2:kde-format");
+  xgettext_record_flag ("ki18np:1:kde-format");
+  xgettext_record_flag ("ki18ncp:2:kde-format");
+  xgettext_record_flag ("ki18nd:2:kde-format");
+  xgettext_record_flag ("ki18ndc:3:kde-format");
+  xgettext_record_flag ("ki18ndp:2:kde-format");
+  xgettext_record_flag ("ki18ndcp:3:kde-format");
+  xgettext_record_flag ("I18N_NOOP:1:kde-format");
+  xgettext_record_flag ("I18NC_NOOP:2:kde-format");
+  xgettext_record_flag ("I18N_NOOP2:2:kde-format");
+  xgettext_record_flag ("I18N_NOOP2_NOSTRIP:2:kde-format");
+  xgettext_record_flag ("xi18n:1:kde-kuit-format");
+  xgettext_record_flag ("xi18nc:2:kde-kuit-format");
+  xgettext_record_flag ("xi18np:1:kde-kuit-format");
+  xgettext_record_flag ("xi18ncp:2:kde-kuit-format");
+  xgettext_record_flag ("xi18nd:2:kde-kuit-format");
+  xgettext_record_flag ("xi18ndc:3:kde-kuit-format");
+  xgettext_record_flag ("xi18ndp:2:kde-kuit-format");
+  xgettext_record_flag ("xi18ndcp:3:kde-kuit-format");
+  xgettext_record_flag ("kxi18n:1:kde-kuit-format");
+  xgettext_record_flag ("kxi18nc:2:kde-kuit-format");
+  xgettext_record_flag ("kxi18np:1:kde-kuit-format");
+  xgettext_record_flag ("kxi18ncp:2:kde-kuit-format");
+  xgettext_record_flag ("kxi18nd:2:kde-kuit-format");
+  xgettext_record_flag ("kxi18ndc:3:kde-kuit-format");
+  xgettext_record_flag ("kxi18ndp:2:kde-kuit-format");
+  xgettext_record_flag ("kxi18ndcp:3:kde-kuit-format");
+  xgettext_record_flag ("XI18N_NOOP:1:kde-kuit-format");
+  xgettext_record_flag ("XI18NC_NOOP:2:kde-kuit-format");
+  xgettext_record_flag ("XI18N_NOOP2:2:kde-kuit-format");
+  xgettext_record_flag ("XI18N_NOOP2_NOSTRIP:2:kde-kuit-format");
+}
 
 /* ======================== Reading of characters.  ======================== */
 
diff --git a/gettext-tools/src/x-c.h b/gettext-tools/src/x-c.h
index 9e819a0..3812f7b 100644
--- a/gettext-tools/src/x-c.h
+++ b/gettext-tools/src/x-c.h
@@ -84,9 +84,12 @@ extern void x_objc_keyword (const char *name);
 
 extern void x_c_trigraphs (void);
 
+extern void activate_additional_keywords_kde (void);
+
 extern void init_flag_table_c (void);
 extern void init_flag_table_objc (void);
 extern void init_flag_table_gcc_internal (void);
+extern void init_flag_table_kde (void);
 
 
 extern struct literalstring_parser literalstring_c;
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index 1c9830e..317b648 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -336,6 +336,7 @@ main (int argc, char *argv[])
   init_flag_table_c ();
   init_flag_table_objc ();
   init_flag_table_gcc_internal ();
+  init_flag_table_kde ();
   init_flag_table_sh ();
   init_flag_table_python ();
   init_flag_table_lisp ();
@@ -583,6 +584,7 @@ main (int argc, char *argv[])
 
       case CHAR_MAX + 10:       /* --kde */
         recognize_format_kde = true;
+        activate_additional_keywords_kde ();
         break;
 
       case CHAR_MAX + 11:       /* --boost */

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to