]> git.lyx.org Git - lyx.git/blob - src/gettext.C
* languages: use nb_NO instead of no_NO for norwegian (bug 2850).
[lyx.git] / src / gettext.C
1 /**
2  * \file src/gettext.C
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
21 namespace lyx {
22
23 #ifdef HAVE_LOCALE_H
24 #  include <locale.h>
25 #endif
26
27 using support::setEnv;
28
29 using std::string;
30
31
32 namespace {
33
34 static Messages & getLyXMessages()
35 {
36         static Messages lyx_messages;
37
38         return lyx_messages;
39 }
40
41 } // anon namespace
42
43
44 docstring const _(string const & str)
45 {
46         return getLyXMessages().get(str);
47 }
48
49
50 #ifdef ENABLE_NLS
51
52 void locale_init()
53 {
54         // Disable, as otherwise it overrides everything else incl. the doc language
55         setEnv("LANGUAGE", "");
56 #  ifdef HAVE_LC_MESSAGES
57         setlocale(LC_MESSAGES, "");
58 #  endif
59         setlocale(LC_CTYPE, "");
60         setlocale(LC_NUMERIC, "C");
61 }
62
63 #else // ENABLE_NLS
64
65 void locale_init()
66 {
67         setlocale(LC_NUMERIC, "C");
68 }
69
70 #endif
71
72
73 docstring const translateIfPossible(docstring const & name)
74 {
75         if (support::isAscii(name))
76                 // Probably from a standard configuration file, try to
77                 // translate
78                 return _(to_ascii(name));
79         else
80                 // This must be from a user defined configuration file. We
81                 // cannot translate this, since gettext accepts only ascii
82                 // keys.
83                 return name;
84 }
85
86
87 } // namespace lyx