]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New functions for inspecting supported format types.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Oct 2007 15:15:35 +0000 (15:15 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:21 +0000 (12:15 +0200)
NEWS
gettext-tools/libgettextpo/ChangeLog
gettext-tools/libgettextpo/gettext-po.c
gettext-tools/libgettextpo/gettext-po.h.in

diff --git a/NEWS b/NEWS
index 2820eec1d3025b9d3247ce690b48b0412665eaaf..d0b6374c577b37d8ab7733fad0e2bd534b973775 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ Version 0.16.2 - January 2007
     xgettext has a new option --kde that triggers the recognition and marking
     of KDE 4 format strings.
 
+* libgettextpo library:
+  - New functions are available for querying the list of supported format
+    types.
+
 * Documentation:
   - The "Users" chapter has been completely rewritten.
   - A complete example showing the use of GNU gettext in Java with the Qt/Jambi
index 381b99be3e9ebd41395892a655ad177312fe4399..50e2c2a4f1c20ca6465156024f31a186f8283748 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-21  Bruno Haible  <bruno@clisp.org>
+
+       * gettext-po.h.in (LIBGETTEXTPO_VERSION): Bump version number.
+       (po_format_list, po_format_pretty_name): New declarations.
+       * gettext-po.c: Include xvasprintf.h.
+       (po_format_list, po_format_pretty_name): New functions.
+       Reported by Dwayne Bailey <dwayne@translate.org.za>.
+
 2007-10-20  Bruno Haible  <bruno@clisp.org>
 
        * gettext-po.c (po_message_check_format): Update call to check_message,
index a4ca30088cc57fa0fe2f729ce8ae0284fe56449e..cb5091b3565bc36e3125323b0e3cfce8161c2501 100644 (file)
@@ -40,6 +40,7 @@
 #include "po-error.h"
 #include "po-xerror.h"
 #include "format.h"
+#include "xvasprintf.h"
 #include "msgl-check.h"
 #include "gettext.h"
 
@@ -1112,6 +1113,45 @@ po_filepos_start_line (po_filepos_t filepos)
 }
 
 
+/* Return a NULL terminated array of the supported format types.  */
+
+const char * const *
+po_format_list (void)
+{
+  static const char * const * whole_list /* = NULL */;
+  if (whole_list == NULL)
+    {
+      const char **list = XNMALLOC (NFORMATS + 1, const char *);
+      size_t i;
+      for (i = 0; i < NFORMATS; i++)
+       list[i] = xasprintf ("%s-format", format_language[i]);
+      list[i] = NULL;
+      whole_list = list;
+    }
+  return whole_list;
+}
+
+
+/* Return the pretty name associated with a format type.
+   For example, for "csharp-format", return "C#".
+   Return NULL if the argument is not a supported format type.  */
+
+const char *
+po_format_pretty_name (const char *format_type)
+{
+  size_t len = strlen (format_type);
+  size_t i;
+
+  if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0)
+    for (i = 0; i < NFORMATS; i++)
+      if (strlen (format_language[i]) == len - 7
+         && memcmp (format_language[i], format_type, len - 7) == 0)
+       /* The given format_type corresponds to (enum format_type) i.  */
+       return format_language_pretty[i];
+  return NULL;
+}
+
+
 /* Test whether an entire file PO file is valid, like msgfmt does it.
    If it is invalid, pass the reasons to the handler.  */
 
index 433356b56182079304df1795d27f68c84b4442d9..679895f6305eb1149d7cdc745c5b901d84390f46 100644 (file)
@@ -1,5 +1,5 @@
 /* Public API for GNU gettext PO files - contained in libgettextpo.
-   Copyright (C) 2003-2006 Free Software Foundation, Inc.
+   Copyright (C) 2003-2007 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@ extern "C" {
 /* =========================== Meta Information ============================ */
 
 /* Version number: (major<<16) + (minor<<8) + subminor */
-#define LIBGETTEXTPO_VERSION 0x001000
+#define LIBGETTEXTPO_VERSION 0x001002
 extern int libgettextpo_version;
 
 /* ================================= Types ================================= */
@@ -312,6 +312,17 @@ extern const char * po_filepos_file (po_filepos_t filepos);
 extern size_t po_filepos_start_line (po_filepos_t filepos);
 
 
+/* ============================ Format type API ============================= */
+
+/* Return a NULL terminated array of the supported format types.  */
+extern const char * const * po_format_list (void);
+
+/* Return the pretty name associated with a format type.
+   For example, for "csharp-format", return "C#".
+   Return NULL if the argument is not a supported format type.  */
+extern const char * po_format_pretty_name (const char *format_type);
+
+
 /* ============================= Checking API ============================== */
 
 /* Test whether an entire file PO file is valid, like msgfmt does it.