]> git.lyx.org Git - lyx.git/blob - src/support/gettext.cpp
add debug function which prints the callstack to stderr, disabled by default
[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         if (support::packageInitialized()) {
42                 Messages::init();
43         }
44 #endif
45         setlocale(LC_NUMERIC, "C");
46 }
47
48
49 docstring const translateIfPossible(docstring const & name)
50 {
51         if (support::isAscii(name) && !name.empty())
52                 // Probably from a standard configuration file, try to
53                 // translate
54                 return _(to_ascii(name));
55         else
56                 // This must be from a user defined configuration file. We
57                 // cannot translate this, since gettext accepts only ascii
58                 // keys.
59                 return name;
60 }
61
62
63 docstring const translateIfPossible(docstring const & name, std::string const & language)
64 {
65         if (support::isAscii(name) && !name.empty())
66                 // Probably from a standard configuration file, try to
67                 // translate
68                 return getMessages(language).get(to_ascii(name));
69         else
70                 // This must be from a user defined configuration file. We
71                 // cannot translate this, since gettext accepts only ascii
72                 // keys.
73                 return name;
74 }
75
76
77 } // namespace lyx