1
// i18n.hh for Fluxbox Window Manager
2
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
4
// i18n.cc for Blackbox - an X11 Window manager
5
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
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:
14
// The above copyright notice and this permission notice shall be included in
15
// all copies or substantial portions of the Software.
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.
25
// $Id: i18n.cc,v 1.2 2002/01/09 14:11:20 fluxgen Exp $
27
// stupid macros needed to access some functions in version 2 of the GNU C
34
# include "../config.h"
35
#endif // HAVE_CONFIG_H
39
#include <X11/Xlocale.h>
45
#endif // STDC_HEADERS
49
#endif // HAVE_LOCALE_H
52
void NLSInit(const char *catalog) {
53
I18n *i18n = I18n::instance();
54
i18n->openCatalog(catalog);
60
locale = setlocale(LC_ALL, "");
62
fprintf(stderr, "failed to set locale, reverting to \"C\"\n");
63
#endif // HAVE_SETLOCALE
67
} else if (! strcmp(locale, "C") || ! strcmp(locale, "POSIX")) {
71
// truncate any encoding off the end of the locale
72
char *l = strchr(locale, '.');
75
#endif // HAVE_SETLOCALE
77
catalog_filename = (char *) 0;
78
catalog_fd = (nl_catd) -1;
83
delete catalog_filename;
85
#if defined(NLS) && defined(HAVE_CATCLOSE)
86
if (catalog_fd != (nl_catd) -1)
88
#endif // HAVE_CATCLOSE
91
I18n *I18n::instance() {
92
static I18n singleton; //singleton object
96
void I18n::openCatalog(const char *catalog) {
97
#if defined(NLS) && defined(HAVE_CATOPEN)
98
int lp = strlen(LOCALEPATH), lc = strlen(locale),
99
ct = strlen(catalog), len = lp + lc + ct + 3;
100
catalog_filename = new char[len];
102
strncpy(catalog_filename, LOCALEPATH, lp);
103
*(catalog_filename + lp) = '/';
104
strncpy(catalog_filename + lp + 1, locale, lc);
105
*(catalog_filename + lp + lc + 1) = '/';
106
strncpy(catalog_filename + lp + lc + 2, catalog, ct + 1);
109
catalog_fd = catopen(catalog_filename, MCLoadBySet);
110
# else // !MCLoadBySet
111
catalog_fd = catopen(catalog_filename, NL_CAT_LOCALE);
112
# endif // MCLoadBySet
114
if (catalog_fd == (nl_catd) -1)
115
fprintf(stderr, "failed to open catalog, using default messages\n");
117
#else // !HAVE_CATOPEN
118
catalog_fd = (nl_catd) -1;
119
catalog_filename = (char *) 0;
120
#endif // HAVE_CATOPEN
124
const char *I18n::getMessage(int set, int msg, const char *s) {
125
#if defined(NLS) && defined(HAVE_CATGETS)
126
if (catalog_fd != (nl_catd) -1)
127
return (const char *) catgets(catalog_fd, set, msg, s);