]> git.lyx.org Git - lyx.git/blob - src/gettext.C
Fix working of the spellchecker dialog with ispell when there are no
[lyx.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 #include "LString.h"
14
15 #ifdef ENABLE_NLS
16
17 #  if HAVE_GETTEXT
18 #    include <libintl.h>      // use the header already in the system *EK*
19 #    ifdef HAVE_LOCALE_H
20 #      include <locale.h>        // for LC_MESSAGES
21 #    endif
22 #  else
23 #    include "../intl/libintl.h"
24 #  endif
25
26 char const * _(char const * str)
27 {
28         // I'd rather have an Assert on str, we should not allow
29         // null pointers here. Lgb
30         // Assert(str);
31         if (str && str[0])
32                 return gettext(str);
33         else
34                 return "";
35 }
36
37
38 string const _(string const & str) 
39 {
40         if (!str.empty()) {
41                 int const s = str.length();
42                 char * tmp = new char[s + 1];
43                 str.copy(tmp, s);
44                 tmp[s] = '\0';
45                 string const ret(gettext(tmp));
46                 delete [] tmp;
47                 return ret;
48         } else {
49                 return string();
50         }
51 }
52
53 void locale_init()
54 {
55 #  ifdef HAVE_LC_MESSAGES
56         setlocale(LC_MESSAGES, "");
57         setlocale(LC_CTYPE, "");
58         setlocale(LC_NUMERIC, "C");
59 #  endif
60 }
61
62 void gettext_init(string const & localedir)
63 {
64         bindtextdomain(PACKAGE, localedir.c_str()); 
65         textdomain(PACKAGE);
66 }
67
68
69 #else // ENABLE_NLS
70
71 void locale_init()
72 {
73 }
74
75 void gettext_init(string const &)
76 {
77 }
78 #endif