[vlc-commits] Implement vlc_ngettext() to deal with plurals

Rémi Denis-Courmont git at videolan.org
Mon Apr 16 17:03:33 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Apr 16 18:02:50 2012 +0300| [86c47f64c5a1067f6c19cdbb5c22f3b8cc1cfb43] | committer: Rémi Denis-Courmont

Implement vlc_ngettext() to deal with plurals

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=86c47f64c5a1067f6c19cdbb5c22f3b8cc1cfb43
---

 include/vlc_common.h     |    3 ++-
 po/Makevars              |    2 +-
 src/libvlccore.sym       |    1 +
 src/modules/textdomain.c |   15 +++++++++++----
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index d73000d..9469c18 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -918,7 +918,8 @@ VLC_API void * vlc_memcpy( void *, const void *, size_t );
 /*****************************************************************************
  * I18n stuff
  *****************************************************************************/
-VLC_API char * vlc_gettext( const char *msgid ) VLC_FORMAT_ARG(1);
+VLC_API char *vlc_gettext( const char *msgid ) VLC_FORMAT_ARG(1);
+VLC_API char *vlc_ngettext( const char *s, const char *p, unsigned long n ) VLC_FORMAT_ARG(1) VLC_FORMAT_ARG(2);
 
 #define vlc_pgettext( ctx, id ) \
         vlc_pgettext_aux( ctx "\004" id, id )
diff --git a/po/Makevars b/po/Makevars
index 8781f1e..2d73fe1 100644
--- a/po/Makevars
+++ b/po/Makevars
@@ -10,7 +10,7 @@ subdir = po
 top_builddir = ..
 
 # These options get passed to xgettext.
-XGETTEXT_OPTIONS = --directory=.. --keyword=_ --keyword=N_ --keyword=_NS --keyword=_ANS --keyword=qtr --keyword=Q_ --language=C++ --keyword=vlc_pgettext:1c,2 --add-comments=xgettext: --from-code=UTF-8
+XGETTEXT_OPTIONS = --directory=.. --keyword=_ --keyword=N_ --keyword=_NS --keyword=_ANS --keyword=qtr --keyword=Q_ --language=C++ --keyword=vlc_ngettext:1,2 --keyword=vlc_pgettext:1c,2 --add-comments=xgettext: --from-code=UTF-8
 
 # This is the copyright holder that gets inserted into the header of the
 # $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a167424..373e147 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -537,6 +537,7 @@ vlc_GetActionId
 vlc_getaddrinfo
 vlc_getnameinfo
 vlc_gettext
+vlc_ngettext
 vlc_hold
 vlc_iconv
 vlc_iconv_close
diff --git a/src/modules/textdomain.c b/src/modules/textdomain.c
index 3bf4090..77b83de 100644
--- a/src/modules/textdomain.c
+++ b/src/modules/textdomain.c
@@ -97,10 +97,17 @@ int vlc_bindtextdomain (const char *domain)
 char *vlc_gettext (const char *msgid)
 {
 #ifdef ENABLE_NLS
-    if (unlikely(!*msgid))
-        return (char *)"";
-    return dgettext (PACKAGE_NAME, msgid);
-#else
+    if (likely(*msgid))
+        return dgettext (PACKAGE_NAME, msgid);
+#endif
     return (char *)msgid;
+}
+
+char *vlc_ngettext (const char *msgid, const char *plural, unsigned long n)
+{
+#ifdef ENABLE_NLS
+    if (likely(*msgid))
+        return dngettext (PACKAGE_NAME, msgid, plural, n);
 #endif
+    return (char *)((n == 1) ? msgid : plural);
 }



More information about the vlc-commits mailing list