From: Karel Zak Date: Tue, 25 Apr 2017 15:05:09 +0000 (+0200) Subject: libfdisk: fix NLS support X-Git-Tag: v2.30-rc1~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7095232d21232ca1ab307fbdd1a36471347f23c6;p=thirdparty%2Futil-linux.git libfdisk: fix NLS support The current libfdisk code uses gettext() to translate strings. It means it follows the default text domain (as set by textdomain(3) usually in the main program). This is useless for public shared library. We have call private bindtextdomain() and use dgettext() with private domain name to be independent on the main program. For this purpose include/nls.h supports UL_TEXTDOMAIN_EXPLICIT to use dgettext(). Note that libfdisk will continue to use util-linux.po, rather than keep the texts in the separate file. The nls.h has to be included only from fdiskP.h to be sure that nls.h works as expected for the library. Signed-off-by: Karel Zak --- diff --git a/include/nls.h b/include/nls.h index 3eabfe63b3..50f4f29f7b 100644 --- a/include/nls.h +++ b/include/nls.h @@ -20,9 +20,19 @@ struct lconv # define localeconv() NULL #endif + #ifdef ENABLE_NLS # include -# define _(Text) gettext (Text) +/* + * For NLS support in the public shared libraries we have to specify text + * domain name to be independend on the main program. For this purpose define + * UL_TEXTDOMAIN_EXPLICIT before you include nls.h to your shared library code. + */ +# ifdef UL_TEXTDOMAIN_EXPLICIT +# define _(Text) dgettext (UL_TEXTDOMAIN_EXPLICIT, Text) +# else +# define _(Text) gettext (Text) +# endif # ifdef gettext_noop # define N_(String) gettext_noop (String) # else @@ -37,7 +47,7 @@ struct lconv # define _(Text) (Text) # define N_(Text) (Text) # define P_(Singular, Plural, n) ((n) == 1 ? (Singular) : (Plural)) -#endif +#endif /* ENABLE_NLS */ #ifdef HAVE_LANGINFO_H # include diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c index 0a2563ddea..6fe9c2a6d1 100644 --- a/libfdisk/src/bsd.c +++ b/libfdisk/src/bsd.c @@ -16,7 +16,6 @@ #include #include -#include "nls.h" #include "blkdev.h" #include "fdiskP.h" #include "pt-mbr.h" diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 5ea8dccd42..7dc16aa78a 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -61,6 +61,8 @@ struct fdisk_context *fdisk_new_context(void) cxt->labels[ cxt->nlabels++ ] = fdisk_new_sgi_label(cxt); cxt->labels[ cxt->nlabels++ ] = fdisk_new_sun_label(cxt); + bindtextdomain(LIBFDISK_TEXTDOMAIN, LOCALEDIR); + return cxt; } diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 8f54f7369e..11db99ce10 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -7,7 +7,6 @@ * from util-linux fdisk. */ #include "c.h" -#include "nls.h" #include "randutils.h" #include "pt-mbr.h" #include "strutils.h" diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 949475d15d..eec3ea877f 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -20,7 +20,6 @@ #include "c.h" #include "libfdisk.h" -#include "nls.h" /* temporary before dialog API will be implemented */ #include "list.h" #include "debug.h" #include @@ -47,6 +46,18 @@ UL_DEBUG_DECLARE_MASK(libfdisk); #define ON_DBG(m, x) __UL_DBG_CALL(libfdisk, LIBFDISK_DEBUG_, m, x) #define DBG_FLUSH __UL_DBG_FLUSH(libfdisk, LIBFDISK_DEBUG_) +/* + * NLS -- the library has to be independent on main program, so define + * UL_TEXTDOMAIN_EXPLICIT before you include nls.h. + * + * Now we use util-linux.po (=PACKAGE), rather than maintain the texts + * in the separate libfdisk.po file. + */ +#define LIBFDISK_TEXTDOMAIN PACKAGE +#define UL_TEXTDOMAIN_EXPLICIT LIBFDISK_TEXTDOMAIN +#include "nls.h" + + #ifdef TEST_PROGRAM struct fdisk_test { const char *name; diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index c007347e34..96e6f21bda 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -21,7 +21,6 @@ #include "fdiskP.h" -#include "nls.h" #include "crc32.h" #include "blkdev.h" #include "bitops.h" diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c index d894cf90d8..5b4be6c3a3 100644 --- a/libfdisk/src/parttype.c +++ b/libfdisk/src/parttype.c @@ -1,7 +1,6 @@ #include -#include "nls.h" #include "fdiskP.h" /** diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c index 0ccf245070..eca112a243 100644 --- a/libfdisk/src/sgi.c +++ b/libfdisk/src/sgi.c @@ -12,7 +12,6 @@ */ #include "c.h" -#include "nls.h" #include "all-io.h" #include "blkdev.h" diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index 5414a927c6..a3a5b401e5 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -12,7 +12,6 @@ #include /* write */ #include /* ioctl */ -#include "nls.h" #include "blkdev.h" #include "bitops.h"