aboutsummaryrefslogtreecommitdiff
path: root/src/I18n.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2004-06-07 11:46:05 (GMT)
committerrathnor <rathnor>2004-06-07 11:46:05 (GMT)
commitfff4456dee29e675d7f2ed3490db39bcb7e10e53 (patch)
tree2d2dbf386551773cbdc8231b2a93b493187bd733 /src/I18n.cc
parent073065ac56b388db1169108d44f37d32f1d19c67 (diff)
downloadfluxbox-fff4456dee29e675d7f2ed3490db39bcb7e10e53.zip
fluxbox-fff4456dee29e675d7f2ed3490db39bcb7e10e53.tar.bz2
update NLS string handling...
Diffstat (limited to 'src/I18n.cc')
-rw-r--r--src/I18n.cc140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/I18n.cc b/src/I18n.cc
deleted file mode 100644
index 43f8cea..0000000
--- a/src/I18n.cc
+++ /dev/null
@@ -1,140 +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.6 2004/01/21 14:12:51 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#include <iostream>
41
42#include "defaults.hh"
43
44using std::cerr;
45using std::endl;
46using std::string;
47
48void NLSInit(const char *catalog) {
49 I18n *i18n = I18n::instance();
50 i18n->openCatalog(catalog);
51}
52
53
54I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) {
55#ifdef HAVE_SETLOCALE
56 //make sure we don't get 0 to m_locale string
57 char *temp = setlocale(LC_ALL, "");
58 m_locale = ( temp ? temp : "");
59 if (m_locale.empty()) {
60 cerr<<"Warning: Failed to set locale, reverting to \"C\""<<endl;
61#endif // HAVE_SETLOCALE
62
63 m_locale = "C";
64
65#ifdef HAVE_SETLOCALE
66
67 } else {
68 // MB_CUR_MAX returns the size of a char in the current locale
69 if (MB_CUR_MAX > 1)
70 m_multibyte = true;
71
72 // truncate any encoding off the end of the locale
73
74 // remove everything after @
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 // remove everything after .
79 index = m_locale.find('.');
80 if (index != string::npos)
81 m_locale.erase(index); //erase all characters starting at index
82 // remove everything before =
83 index = m_locale.find('=');
84 if (index != string::npos)
85 m_locale.erase(0,index+1); //erase all characters starting up to index
86 }
87#endif // HAVE_SETLOCALE
88}
89
90
91I18n::~I18n() {
92
93#if defined(NLS) && defined(HAVE_CATCLOSE)
94 if (m_catalog_fd != (nl_catd)-1)
95 catclose(m_catalog_fd);
96#endif // HAVE_CATCLOSE
97}
98
99I18n *I18n::instance() {
100 static I18n singleton; //singleton object
101 return &singleton;
102}
103
104void I18n::openCatalog(const char *catalog) {
105#if defined(NLS) && defined(HAVE_CATOPEN)
106
107 string catalog_filename = LOCALEPATH;
108 catalog_filename += '/';
109 catalog_filename += m_locale;
110 catalog_filename += '/';
111 catalog_filename += catalog;
112
113#ifdef MCLoadBySet
114 m_catalog_fd = catopen(catalog_filename.c_str(), MCLoadBySet);
115#else // !MCLoadBySet
116 m_catalog_fd = catopen(catalog_filename.c_str(), NL_CAT_LOCALE);
117#endif // MCLoadBySet
118
119 if (m_catalog_fd == (nl_catd)-1) {
120 cerr<<"Warning: Failed to open file("<<catalog_filename<<")"<<endl;
121 cerr<<"for translation, using default messages."<<endl;
122 }
123
124#else // !HAVE_CATOPEN
125
126 m_catalog_fd = (nl_catd)-1;
127#endif // HAVE_CATOPEN
128}
129
130
131const char *I18n::getMessage(int set_number, int message_number,
132 const char *default_message) const {
133
134#if defined(NLS) && defined(HAVE_CATGETS)
135 if (m_catalog_fd != (nl_catd)-1)
136 return (const char *) catgets(m_catalog_fd, set_number, message_number, default_message);
137 else
138#endif // NLS && HAVE_CATGETS
139 return default_message;
140}