]> git.lyx.org Git - features.git/blob - src/gettext.C
skak support, John's ERT fixes, loclae blunder fix
[features.git] / src / gettext.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *        
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef HAVE_LOCALE_H
14 #  include <locale.h>
15 #endif
16
17 #include "LString.h"
18
19 #ifdef ENABLE_NLS
20
21 #  if HAVE_GETTEXT
22 #    include <libintl.h>      // use the header already in the system *EK*
23 #  else
24 #    include "../intl/libintl.h"
25 #  endif
26
27 char const * _(char const * str)
28 {
29         // I'd rather have an Assert on str, we should not allow
30         // null pointers here. Lgb
31         // Assert(str);
32         if (str && str[0])
33                 return gettext(str);
34         else
35                 return "";
36 }
37
38
39 string const _(string const & str) 
40 {
41         if (!str.empty()) {
42                 int const s = str.length();
43                 char * tmp = new char[s + 1];
44                 str.copy(tmp, s);
45                 tmp[s] = '\0';
46                 string const ret(gettext(tmp));
47                 delete [] tmp;
48                 return ret;
49         } else {
50                 return string();
51         }
52 }
53
54 void locale_init()
55 {
56 #  ifdef HAVE_LC_MESSAGES
57         setlocale(LC_MESSAGES, "");
58 #  endif
59         setlocale(LC_CTYPE, "");
60         setlocale(LC_NUMERIC, "C");
61 }
62
63 void gettext_init(string const & localedir)
64 {
65         bindtextdomain(PACKAGE, localedir.c_str()); 
66         textdomain(PACKAGE);
67 }
68
69
70 #else // ENABLE_NLS
71
72 void locale_init()
73 {
74         setlocale(LC_NUMERIC, "C");
75 }
76
77 void gettext_init(string const &)
78 {
79 }
80 #endif