]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix NLS support
authorKarel Zak <kzak@redhat.com>
Tue, 25 Apr 2017 15:05:09 +0000 (17:05 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 25 Apr 2017 15:05:09 +0000 (17:05 +0200)
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 <kzak@redhat.com>
include/nls.h
libfdisk/src/bsd.c
libfdisk/src/context.c
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/parttype.c
libfdisk/src/sgi.c
libfdisk/src/sun.c

index 3eabfe63b3ee9748f780ab1ed26578c9a94c0c0e..50f4f29f7bbd9d6b0f36f17bd09c83dacbca0f20 100644 (file)
@@ -20,9 +20,19 @@ struct lconv
 # define localeconv() NULL
 #endif
 
+
 #ifdef ENABLE_NLS
 # include <libintl.h>
-# 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 <langinfo.h>
index 0a2563ddeae468a60c3c32e09638d875874d4c6c..6fe9c2a6d1c453725d2382fb8f84ba56444be83c 100644 (file)
@@ -16,7 +16,6 @@
 #include <errno.h>
 #include <sys/param.h>
 
-#include "nls.h"
 #include "blkdev.h"
 #include "fdiskP.h"
 #include "pt-mbr.h"
index 5ea8dccd424ed0c557d78d8aadccae917b1345c8..7dc16aa78a38b86df85256aaad784183eb8abbc4 100644 (file)
@@ -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;
 }
 
index 8f54f7369e049587ca10b0880518eeeea7e7631c..11db99ce10cad726d1c33cf17fe6efbe7c51407c 100644 (file)
@@ -7,7 +7,6 @@
  * from util-linux fdisk.
  */
 #include "c.h"
-#include "nls.h"
 #include "randutils.h"
 #include "pt-mbr.h"
 #include "strutils.h"
index 949475d15d525ebc36238de3bde164a7dcd27802..eec3ea877fd4926d23440dca340ed8a7039add82 100644 (file)
@@ -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 <stdio.h>
@@ -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;
index c007347e3428c671610f1cebf31ebe24d5e7b1bc..96e6f21bdad03cfe3c66b3b1b76da791ff46d9fb 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "fdiskP.h"
 
-#include "nls.h"
 #include "crc32.h"
 #include "blkdev.h"
 #include "bitops.h"
index d894cf90d84b2b2af1ab9a08211d11882bbccef8..5b4be6c3a3ab5dfe95fca7e43ce5f3b9da7611dd 100644 (file)
@@ -1,7 +1,6 @@
 
 #include <ctype.h>
 
-#include "nls.h"
 #include "fdiskP.h"
 
 /**
index 0ccf2450705137d33349761ffb5d479f9a38dfbe..eca112a243419de3f29b3593249f9a34043af5d3 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "c.h"
-#include "nls.h"
 #include "all-io.h"
 
 #include "blkdev.h"
index 5414a927c62d580c7bc486cfb681c5d0fbcb86b7..a3a5b401e5d19916d5a4b793e64b91144cc009c4 100644 (file)
@@ -12,7 +12,6 @@
 #include <unistd.h>            /* write */
 #include <sys/ioctl.h>         /* ioctl */
 
-#include "nls.h"
 #include "blkdev.h"
 #include "bitops.h"