diff options
Diffstat (limited to 'src/i18n.cc')
-rw-r--r-- | src/i18n.cc | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/src/i18n.cc b/src/i18n.cc deleted file mode 100644 index 833a094..0000000 --- a/src/i18n.cc +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | // i18n.hh for Fluxbox Window Manager | ||
2 | // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) | ||
3 | // | ||
4 | // i18n.cc for Blackbox - an X11 Window manager | ||
5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | ||
6 | // | ||
7 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | // copy of this software and associated documentation files (the "Software"), | ||
9 | // to deal in the Software without restriction, including without limitation | ||
10 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | // and/or sell copies of the Software, and to permit persons to whom the | ||
12 | // Software is furnished to do so, subject to the following conditions: | ||
13 | // | ||
14 | // The above copyright notice and this permission notice shall be included in | ||
15 | // all copies or substantial portions of the Software. | ||
16 | // | ||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
20 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | // DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | // $Id: i18n.cc,v 1.10 2003/05/16 00:17:16 fluxgen Exp $ | ||
26 | |||
27 | //usr GNU extensions | ||
28 | #ifndef _GNU_SOURCE | ||
29 | #define _GNU_SOURCE | ||
30 | #endif // _GNU_SOURCE | ||
31 | |||
32 | #include "i18n.hh" | ||
33 | |||
34 | #include <X11/Xlocale.h> | ||
35 | |||
36 | #include <cstdlib> | ||
37 | #include <cstring> | ||
38 | #include <cstdio> | ||
39 | |||
40 | #ifdef HAVE_LOCALE_H | ||
41 | #include <locale.h> | ||
42 | #endif // HAVE_LOCALE_H | ||
43 | |||
44 | #include <iostream> | ||
45 | using std::cerr; | ||
46 | using std::endl; | ||
47 | using std::string; | ||
48 | |||
49 | void NLSInit(const char *catalog) { | ||
50 | I18n *i18n = I18n::instance(); | ||
51 | i18n->openCatalog(catalog); | ||
52 | } | ||
53 | |||
54 | |||
55 | I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) { | ||
56 | #ifdef HAVE_SETLOCALE | ||
57 | //make sure we don't get 0 to m_locale string | ||
58 | char *temp = setlocale(LC_ALL, ""); | ||
59 | m_locale = ( temp ? temp : ""); | ||
60 | if (m_locale.size() == 0) { | ||
61 | cerr<<"Warning: Failed to set locale, reverting to \"C\""<<endl; | ||
62 | #endif // HAVE_SETLOCALE | ||
63 | |||
64 | m_locale = "C"; | ||
65 | |||
66 | #ifdef HAVE_SETLOCALE | ||
67 | |||
68 | } else { | ||
69 | // MB_CUR_MAX returns the size of a char in the current locale | ||
70 | if (MB_CUR_MAX > 1) | ||
71 | m_multibyte = true; | ||
72 | |||
73 | // truncate any encoding off the end of the locale | ||
74 | |||
75 | string::size_type index = m_locale.find('@'); | ||
76 | if (index != string::npos) | ||
77 | m_locale.erase(index); //erase all characters starting at index | ||
78 | |||
79 | index = m_locale.find('.'); | ||
80 | if (index != string::npos) | ||
81 | m_locale.erase(index); //erase all characters starting at index | ||
82 | } | ||
83 | #endif // HAVE_SETLOCALE | ||
84 | } | ||
85 | |||
86 | |||
87 | I18n::~I18n() { | ||
88 | |||
89 | #if defined(NLS) && defined(HAVE_CATCLOSE) | ||
90 | if (m_catalog_fd != (nl_catd)-1) | ||
91 | catclose(m_catalog_fd); | ||
92 | #endif // HAVE_CATCLOSE | ||
93 | } | ||
94 | |||
95 | I18n *I18n::instance() { | ||
96 | static I18n singleton; //singleton object | ||
97 | return &singleton; | ||
98 | } | ||
99 | |||
100 | void I18n::openCatalog(const char *catalog) { | ||
101 | #if defined(NLS) && defined(HAVE_CATOPEN) | ||
102 | |||
103 | string catalog_filename = LOCALEPATH; | ||
104 | catalog_filename += '/'; | ||
105 | catalog_filename += m_locale; | ||
106 | catalog_filename += '/'; | ||
107 | catalog_filename += catalog; | ||
108 | |||
109 | #ifdef MCLoadBySet | ||
110 | m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet); | ||
111 | #else // !MCLoadBySet | ||
112 | m_catalog_fd = catopen(catalog_filename.c_str(), NL_CAT_LOCALE); | ||
113 | #endif // MCLoadBySet | ||
114 | |||
115 | if (m_catalog_fd == (nl_catd)-1) { | ||
116 | cerr<<"Warning: Failed to open file("<<catalog_filename<<")"<<endl; | ||
117 | cerr<<"for translation, using default messages."<<endl; | ||
118 | } | ||
119 | |||
120 | #else // !HAVE_CATOPEN | ||
121 | |||
122 | m_catalog_fd = (nl_catd)-1; | ||
123 | #endif // HAVE_CATOPEN | ||
124 | } | ||
125 | |||
126 | |||
127 | const char *I18n::getMessage(int set_number, int message_number, | ||
128 | const char *default_message) { | ||
129 | |||
130 | #if defined(NLS) && defined(HAVE_CATGETS) | ||
131 | if (m_catalog_fd != (nl_catd)-1) | ||
132 | return (const char *) catgets(m_catalog_fd, set_number, message_number, default_message); | ||
133 | else | ||
134 | #endif // NLS && HAVE_CATGETS | ||
135 | return default_message; | ||
136 | } | ||