]> git.lyx.org Git - lyx.git/blob - src/gettext.cpp
Correctly generate latex for font/language/encoding switches inside and around
[lyx.git] / src / gettext.cpp
1 /**
2  * \file src/gettext.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "gettext.h"
15 #include "Messages.h"
16
17 #include "support/environment.h"
18 #include "support/lstrings.h"
19
20 #ifdef HAVE_LOCALE_H
21 #  include <locale.h>
22 #endif
23
24 using std::string;
25
26
27 namespace lyx {
28
29 using support::setEnv;
30
31
32 docstring const _(string const & str)
33 {
34         return getGuiMessages().get(str);
35 }
36
37
38 #ifdef ENABLE_NLS
39
40 void locale_init()
41 {
42         // Disable, as otherwise it overrides everything else incl. the doc language
43         setEnv("LANGUAGE", "");
44 #  ifdef HAVE_LC_MESSAGES
45         setlocale(LC_MESSAGES, "");
46 #  endif
47         setlocale(LC_CTYPE, "");
48         setlocale(LC_NUMERIC, "C");
49 }
50
51 #else // ENABLE_NLS
52
53 void locale_init()
54 {
55         setlocale(LC_NUMERIC, "C");
56 }
57
58 #endif
59
60
61 docstring const translateIfPossible(docstring const & name)
62 {
63         if (support::isAscii(name))
64                 // Probably from a standard configuration file, try to
65                 // translate
66                 return _(to_ascii(name));
67         else
68                 // This must be from a user defined configuration file. We
69                 // cannot translate this, since gettext accepts only ascii
70                 // keys.
71                 return name;
72 }
73
74
75 } // namespace lyx