xref: /freebsd/contrib/xz/src/common/tuklib_gettext.h (revision 128836d304d93f2d00eb14069c27089ab46c38d4)
1 // SPDX-License-Identifier: 0BSD
2 
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       tuklib_gettext.h
6 /// \brief      Wrapper for gettext and friends
7 //
8 //  Author:     Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef TUKLIB_GETTEXT_H
13 #define TUKLIB_GETTEXT_H
14 
15 #include "tuklib_common.h"
16 #include <locale.h>
17 
18 #ifndef TUKLIB_GETTEXT
19 #	ifdef ENABLE_NLS
20 #		define TUKLIB_GETTEXT 1
21 #	else
22 #		define TUKLIB_GETTEXT 0
23 #	endif
24 #endif
25 
26 #if TUKLIB_GETTEXT
27 #	include <libintl.h>
28 #	define tuklib_gettext_init(package, localedir) \
29 		do { \
30 			setlocale(LC_ALL, ""); \
31 			bindtextdomain(package, localedir); \
32 			textdomain(package); \
33 		} while (0)
34 #	define _(msgid) gettext(msgid)
35 #else
36 #	define tuklib_gettext_init(package, localedir) \
37 		setlocale(LC_ALL, "")
38 #	define _(msgid) (msgid)
39 #	define ngettext(msgid1, msgid2, n) ((n) == 1 ? (msgid1) : (msgid2))
40 #endif
41 #define N_(msgid) msgid
42 
43 // Optional: Strings that are word wrapped using tuklib_mbstr_wrap may be
44 // marked with W_("foo) in the source code. xgettext can then add a comment
45 // to all such strings to inform translators. The following option needs to
46 // be added to XGETTEXT_OPTIONS in po/Makevars or in an equivalent place:
47 //
48 // '--keyword=W_:1,"This is word wrapped at spaces. The Unicode character U+00A0 works as a non-breaking space. Tab (\t) is interpret as a zero-width space (the tab itself is not displayed); U+200B is NOT supported. Manual word wrapping with \n is supported but requires care."'
49 //
50 // NOTE: The double-quotes in the --keyword argument above must be passed to
51 // xgettext as is, thus one needs the single-quotes in Makevars.
52 #define W_(msgid) _(msgid)
53 
54 #endif
55