]> git.lyx.org Git - lyx.git/blob - src/gettext.C
2ad36ede3bc6b60653de37e8cb948793ec4bcc3b
[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 "messages.h"
14 #include "LString.h"
15 #include "support/LAssert.h"
16
17 #include <boost/scoped_ptr.hpp>
18
19 #ifdef HAVE_LOCALE_H
20 #  include <locale.h>
21 #endif
22
23 namespace {
24
25 boost::scoped_ptr<Messages> lyx_messages;
26
27 } // anon namespace
28
29
30 char const * _(char const * str)
31 {
32         lyx::Assert(str && str[0]);
33
34         if (!lyx_messages.get())
35                 return str;
36
37         return lyx_messages->get(str).c_str();
38 }
39
40
41 string const _(string const & str)
42 {
43         lyx::Assert(!str.empty());
44
45         if (!lyx_messages.get())
46                 return str;
47
48         return lyx_messages->get(str);
49 }
50
51
52 void gettext_init(string const & localedir)
53 {
54         lyx_messages.reset(new Messages("", localedir));
55 }
56
57
58 #ifdef ENABLE_NLS
59
60 void locale_init()
61 {
62 #  ifdef HAVE_LC_MESSAGES
63         setlocale(LC_MESSAGES, "");
64 #  endif
65         setlocale(LC_CTYPE, "");
66         setlocale(LC_NUMERIC, "C");
67 }
68
69 #else // ENABLE_NLS
70
71 void locale_init()
72 {
73         setlocale(LC_NUMERIC, "C");
74 }
75
76 #endif