Debian Codegraph @

libhylafax/NLS.c++

raw
1 /* $Id$ */
2 /*
3 * Copyright (c) 2007 Patrice Fournier
4 * Copyright (c) 2007 iFAX Solutions Inc.
5 * HylaFAX is a trademark of Silicon Graphics
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 *
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE.
25 */
26 #include "NLS.h"
27 #include "Types.h"
28 #include "Sys.h"
29
30 #include <errno.h>
31
32 #ifdef ENABLE_NLS
33 void do_bind (const char* domain, const char* ldir)
34 {
35 /* bindtextdomain() doesn't preserver errno */
36 int save_errno = errno;
37
38 if (!ldir)
39 ldir = getenv("HFLOCALEDIR");
40 if (!ldir)
41 ldir = LOCALEDIR;
42 bindtextdomain(domain, ldir);
43 errno = save_errno;
44 }
45
46 const char* NLS::TEXT (const char* msgid)
47 {
48 if (! bound)
49 {
50 bound = true;
51 do_bind(domain, NULL);
52 }
53 return dgettext(domain, msgid);
54 }
55
56 void NLS::Setup (const char* d, const char* ldir)
57 {
58 setlocale(LC_CTYPE, "");
59 setlocale(LC_MESSAGES, "");
60
61 /*
62 * We'll take the hit of setting up libhylafax NLS here
63 */
64 do_bind(domain, NULL);
65 bound = true;
66
67 do_bind(d, ldir);
68 textdomain(d);
69 }
70
71 const char* NLS::domain = "libhylafax";
72
73 #else
74
75 void NLS::Setup (const char*, const char*)
76 {
77 }
78
79 #endif
80 bool NLS::bound = false;