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