[GRASS-SVN] r59156 - in grass/trunk: include include/defs lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 1 09:55:31 PST 2014


Author: marisn
Date: 2014-03-01 09:55:31 -0800 (Sat, 01 Mar 2014)
New Revision: 59156

Modified:
   grass/trunk/include/defs/glocale.h
   grass/trunk/include/glocale.h
   grass/trunk/lib/gis/locale.c
Log:
Introduce ngettext support and a new macro _n for it

Modified: grass/trunk/include/defs/glocale.h
===================================================================
--- grass/trunk/include/defs/glocale.h	2014-03-01 14:02:28 UTC (rev 59155)
+++ grass/trunk/include/defs/glocale.h	2014-03-01 17:55:31 UTC (rev 59156)
@@ -3,5 +3,6 @@
 
 extern void G_init_locale(void);
 extern char *G_gettext(const char *, const char *) __attribute__((format_arg (2)));
+extern char *G_ngettext(const char *, const char *, const char *, unsigned long int) __attribute__((format_arg (2), format_arg (3)));
 
 #endif

Modified: grass/trunk/include/glocale.h
===================================================================
--- grass/trunk/include/glocale.h	2014-03-01 14:02:28 UTC (rev 59155)
+++ grass/trunk/include/glocale.h	2014-03-01 17:55:31 UTC (rev 59156)
@@ -8,6 +8,7 @@
 #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
 #include <libintl.h>
 #define _(str) G_gettext(PACKAGE,(str))
+#define _n(strs,strp,num) G_ngettext(PACKAGE,(strs),(strp),num)
 #else
 #define _(str) (str)
 #endif

Modified: grass/trunk/lib/gis/locale.c
===================================================================
--- grass/trunk/lib/gis/locale.c	2014-03-01 14:02:28 UTC (rev 59155)
+++ grass/trunk/lib/gis/locale.c	2014-03-01 17:55:31 UTC (rev 59156)
@@ -70,3 +70,24 @@
     return (char *)msgid;
 #endif
 }
+
+/**
+ * \brief Gets localized text with correct plural forms.
+ *
+ * \param[in] package
+ * \param[in] msgids A singular version of string
+ * \param[in] msgidp A plural version of string
+ * \param[in] n The number
+ * \retval char * Pointer to string
+ */
+
+char *G_ngettext(const char *package, const char *msgids, const char *msgidp, unsigned long int n)
+{
+#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
+    G_init_locale();
+
+    return dngettext(package, msgids, msgidp, n);
+#else
+    return n == 1 ? (char *)msgids : (char *)msgidp;
+#endif
+}



More information about the grass-commit mailing list