]> git.lyx.org Git - lyx.git/blob - src/support/gettext.cpp
Don't allow newline characters in document settings.
[lyx.git] / src / support / 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 "support/gettext.h"
15
16 #include "support/lstrings.h"
17 #include "support/Messages.h"
18 #include "support/Package.h"
19
20 #ifdef HAVE_LOCALE_H
21 #  include <locale.h>
22 #endif
23
24 using namespace std;
25
26 namespace lyx {
27
28 docstring const _(string const & str)
29 {
30         return getGuiMessages().get(str);
31 }
32
33
34 void locale_init()
35 {
36 #ifdef ENABLE_NLS
37 #  ifdef HAVE_LC_MESSAGES
38         setlocale(LC_MESSAGES, "");
39 #  endif
40         setlocale(LC_CTYPE, "");
41         Messages::init();
42 #endif
43         setlocale(LC_NUMERIC, "C");
44 }
45
46
47 docstring const translateIfPossible(docstring const & name)
48 {
49         if (support::isAscii(name) && !name.empty())
50                 // Probably from a standard configuration file, try to
51                 // translate
52                 return _(to_ascii(name));
53         else
54                 // This must be from a user defined configuration file. We
55                 // cannot translate this, since gettext accepts only ascii
56                 // keys.
57                 return name;
58 }
59
60
61 docstring const translateIfPossible(docstring const & name, std::string const & language)
62 {
63         if (support::isAscii(name) && !name.empty())
64                 // Probably from a standard configuration file, try to
65                 // translate
66                 return getMessages(language).get(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