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