1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/* Internationalization support routines header.
Copyright by Salvador E. Tropea (SET) (2003-2005)
Covered by the GPL license. */
/* The dummies are in nointl.h to make this header less complex */
#ifndef TVIntl_Included
#define TVIntl_Included
#ifdef FORCE_INTL_SUPPORT
#define HAVE_INTL_SUPPORT 1
#else
#include <tv/configtv.h>
#endif
#ifndef HAVE_INTL_SUPPORT
#include <tv/nointl.h>
#else
#ifdef __cplusplus
struct stTVIntl
{
char *translation;
int cp;
};
const int libPackageNameLen=20;
class CLY_EXPORT TVIntl
{
public:
TVIntl() {};
// Set the domain or catalog of translations (usually the name of the program)
static const char *textDomain(const char *domainname);
// Indicate a directory to search for catalogs
static const char *bindTextDomain(const char *domainname, const char *dirname);
// Translate the message
static const char *getText(const char *msgid);
// What we think is a good way to initialize the domain
static int autoInit(const char *package, const char *localeDir=NULL);
// Special (and tricky members)
// Set the encoding for the catalog
static void setCatalogEncoding(int cp) { forcedCatalogEncoding=cp; };
// Dis/Enable translations
static void enableTranslations() { initialize(); };
static void disableTranslations() { translate=0; };
// Returns a newly allocated string and translated (if enabled)
static char *getTextNew(const char *msgid, Boolean onlyIntl=False);
static const char *getText(const char *msgid, stTVIntl *&cache);
static void freeSt(stTVIntl *&cache);
static stTVIntl *emptySt();
static stTVIntl *dontTranslateSt();
// Replacements that translates and recodes the format string
static int snprintf(char *dest, size_t sz, const char *fmt, ...);
#ifdef Uses_intl_fprintf
static int fprintf(FILE *f, const char *fmt, ...);
#endif
protected:
// Enable translations
static char translate;
// Class already initialized
static char initialized;
// Indicates if the catalog must be recoded to match the application code page.
static char needsRecode;
// Used to change the implicit encoding
static int forcedCatalogEncoding;
// Assumed catalog encoding. This is OS independent and is an arbitrary
// criteria for TV. It makes easier to create portable programs.
static int catalogEncoding;
// Default encodings used for TV. Defined only for the available translations.
static const char *defaultEncodingNames[];
static int defaultEncodings[];
static void *previousCPCallBack;
static uchar recodeTable[256];
static char packageName[libPackageNameLen];
static void initialize();
static void codePageCB(ushort *map);
static void recodeStr(char *str, int len);
};
#ifndef _
#define _(msg) TVIntl::getText(msg)
#endif
#ifndef __
#define __(msg) (msg)
#endif
#ifndef BINDTEXTDOMAIN
#define BINDTEXTDOMAIN(a,b) TVIntl::bindTextDomain(a,b)
#endif
#ifndef TEXTDOMAIN
#define TEXTDOMAIN(a) TVIntl::textDomain(a)
#endif
#else /* __cplusplus */
#ifndef _
#ifdef HAVE_INTL_SUPPORT
char *gettext(const char *msgid);
#define _(msg) gettext(msg)
#else
#define _(msg) (msg)
#endif
#endif
#ifndef __
#define __(msg) (msg)
#endif
#ifndef BINDTEXTDOMAIN
char *bindtextdomain(const char *domainname, const char *dirname);
#define BINDTEXTDOMAIN(a,b) bindtextdomain(a,b)
#endif
#ifndef TEXTDOMAIN
char *textdomain(const char *domainname);
#define TEXTDOMAIN(a) textdomain(a)
#endif
#endif /* __cplusplus */
#endif /* HAVE_INTL_SUPPORT */
#endif /* TVIntl_Included */
|