]> git.lyx.org Git - lyx.git/blob - src/gettext.C
Indentation change + small #ifndef NEW_INSETS fix.
[lyx.git] / src / gettext.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #ifdef ENABLE_NLS
15
16 #include "LString.h"
17
18 #  if HAVE_GETTEXT
19 #    include <libintl.h>      // use the header already in the system *EK*
20 #    ifdef HAVE_LOCALE_H
21 #      include <locale.h>        // for LC_MESSAGES
22 #    endif
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 ret(gettext(tmp));
47                 delete [] tmp;
48                 return ret;
49         }
50         else
51                 return string();
52 }
53
54 void locale_init()
55 {
56 #  ifdef HAVE_LC_MESSAGES
57         setlocale(LC_MESSAGES, "");
58         setlocale(LC_CTYPE, "");
59         setlocale(LC_NUMERIC, "C");
60 #  endif
61 }
62
63 void gettext_init(string const & localedir)
64 {
65         bindtextdomain(PACKAGE, localedir.c_str()); 
66         textdomain(PACKAGE);
67 }
68
69
70 #endif