diff options
author | simonb <simonb> | 2006-06-21 14:41:16 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-06-21 14:41:16 (GMT) |
commit | 3ada3b1f0d6d2debaaab48eecf828a406e964c8e (patch) | |
tree | 3c2f02462317408ee8604d0c7bb41092ecfd1c3a /src/FbTk/I18n.cc | |
parent | 62a298b0b30aa5b4990f462aece224e09e4fafe6 (diff) | |
download | fluxbox-3ada3b1f0d6d2debaaab48eecf828a406e964c8e.zip fluxbox-3ada3b1f0d6d2debaaab48eecf828a406e964c8e.tar.bz2 |
fix nls... notably classify text on conversion whether its for X or
console, plus handle catalogs better.
Diffstat (limited to 'src/FbTk/I18n.cc')
-rw-r--r-- | src/FbTk/I18n.cc | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/FbTk/I18n.cc b/src/FbTk/I18n.cc index 8d05204..7876821 100644 --- a/src/FbTk/I18n.cc +++ b/src/FbTk/I18n.cc | |||
@@ -38,6 +38,7 @@ | |||
38 | #endif // _GNU_SOURCE | 38 | #endif // _GNU_SOURCE |
39 | 39 | ||
40 | #include "I18n.hh" | 40 | #include "I18n.hh" |
41 | #include "FileUtil.hh" | ||
41 | 42 | ||
42 | #include <X11/Xlocale.h> | 43 | #include <X11/Xlocale.h> |
43 | 44 | ||
@@ -72,7 +73,7 @@ void NLSInit(const char *catalog) { | |||
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
75 | I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) { | 76 | I18n::I18n():m_multibyte(false), m_utf8_translate(false), m_catalog_fd((nl_catd)(-1)) { |
76 | #ifdef HAVE_SETLOCALE | 77 | #ifdef HAVE_SETLOCALE |
77 | //make sure we don't get 0 to m_locale string | 78 | //make sure we don't get 0 to m_locale string |
78 | char *temp = setlocale(LC_MESSAGES, ""); | 79 | char *temp = setlocale(LC_MESSAGES, ""); |
@@ -122,13 +123,33 @@ I18n *I18n::instance() { | |||
122 | 123 | ||
123 | void I18n::openCatalog(const char *catalog) { | 124 | void I18n::openCatalog(const char *catalog) { |
124 | #if defined(NLS) && defined(HAVE_CATOPEN) | 125 | #if defined(NLS) && defined(HAVE_CATOPEN) |
125 | 126 | ||
126 | string catalog_filename = LOCALEPATH; | 127 | string catalog_filename = LOCALEPATH; |
127 | catalog_filename += '/'; | 128 | catalog_filename += '/'; |
128 | catalog_filename += m_locale; | 129 | catalog_filename += m_locale; |
129 | catalog_filename += '/'; | 130 | catalog_filename += '/'; |
130 | catalog_filename += catalog; | 131 | catalog_filename += catalog; |
131 | 132 | ||
133 | if (!FileUtil::isRegularFile(catalog_filename.c_str()) && m_locale != "C" && FbStringUtil::haveUTF8()) { | ||
134 | // try the UTF-8 catalog, this also picks up situations where | ||
135 | // the codeset somehow isn't specified | ||
136 | |||
137 | // remove everything after @ | ||
138 | string::size_type index = m_locale.find('.'); | ||
139 | // erase all characters starting at index | ||
140 | if (index != string::npos) | ||
141 | m_locale.erase(index); | ||
142 | |||
143 | m_locale.append(".UTF-8"); | ||
144 | m_utf8_translate = true; | ||
145 | |||
146 | catalog_filename = LOCALEPATH; | ||
147 | catalog_filename += '/'; | ||
148 | catalog_filename += m_locale; | ||
149 | catalog_filename += '/'; | ||
150 | catalog_filename += catalog; | ||
151 | } | ||
152 | |||
132 | #ifdef MCLoadBySet | 153 | #ifdef MCLoadBySet |
133 | m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet); | 154 | m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet); |
134 | #else // !MCLoadBySet | 155 | #else // !MCLoadBySet |
@@ -147,16 +168,29 @@ void I18n::openCatalog(const char *catalog) { | |||
147 | } | 168 | } |
148 | 169 | ||
149 | 170 | ||
171 | // Translate_FB means it'll become an FbString that goes to X for Fonts, | ||
172 | // No translate means it stays in the local encoding, for printing to the | ||
173 | // console. | ||
150 | FbString I18n::getMessage(int set_number, int message_number, | 174 | FbString I18n::getMessage(int set_number, int message_number, |
151 | const char *default_message) const { | 175 | const char *default_message, bool translate_fb) const { |
152 | 176 | ||
153 | #if defined(NLS) && defined(HAVE_CATGETS) | 177 | #if defined(NLS) && defined(HAVE_CATGETS) |
154 | if (m_catalog_fd != (nl_catd)-1) { | 178 | if (m_catalog_fd != (nl_catd)-1) { |
155 | const char *ret = catgets(m_catalog_fd, set_number, message_number, default_message); | 179 | const char *ret = catgets(m_catalog_fd, set_number, message_number, default_message); |
180 | // can't translate, leave it in raw ascii (utf-8 compatible) | ||
156 | if (ret == default_message || ret == NULL) | 181 | if (ret == default_message || ret == NULL) |
157 | return default_message; // don't recode the default | 182 | return default_message; |
158 | 183 | ||
159 | return FbStringUtil::LocaleStrToFb(ret); | 184 | if (!m_utf8_translate && translate_fb) |
185 | // Local input, UTF-8 output | ||
186 | return FbStringUtil::LocaleStrToFb(ret); | ||
187 | else if (m_utf8_translate && !translate_fb) | ||
188 | // UTF-8 input, local output | ||
189 | return FbStringUtil::FbStrToLocale(ret); | ||
190 | else | ||
191 | // UTF-8 input, UTF-8 output OR | ||
192 | // local input, local output | ||
193 | return ret; | ||
160 | } | 194 | } |
161 | else | 195 | else |
162 | #endif // NLS && HAVE_CATGETS | 196 | #endif // NLS && HAVE_CATGETS |