]>
Dogcows Code - chaz/openbox/blob - src/i18n.cc
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
35 #include <X11/Xlocale.h>
41 #endif // STDC_HEADERS
45 #endif // HAVE_LOCALE_H
47 // the rest of bb source uses True and False from X, so we continue that
51 static I18n static_i18n
;
54 void NLSInit(const char *catalog
) {
57 i18n
->openCatalog(catalog
);
64 locale
= setlocale(LC_ALL
, "");
66 fprintf(stderr
, "failed to set locale, reverting to \"C\"\n");
67 #endif // HAVE_SETLOCALE
71 // MB_CUR_MAX returns the size of a char in the current locale
74 // truncate any encoding off the end of the locale
75 char *l
= strchr(locale
, '@');
77 l
= strchr(locale
, '.');
82 catalog_fd
= (nl_catd
) -1;
84 #endif // HAVE_SETLOCALE
86 catalog_filename
= (char *) 0;
91 delete [] catalog_filename
;
93 #if defined(NLS) && defined(HAVE_CATCLOSE)
94 if (catalog_fd
!= (nl_catd
) -1)
96 #endif // HAVE_CATCLOSE
100 void I18n::openCatalog(const char *catalog
) {
101 #if defined(NLS) && defined(HAVE_CATOPEN)
102 int lp
= strlen(LOCALEPATH
), lc
= strlen(locale
),
103 ct
= strlen(catalog
), len
= lp
+ lc
+ ct
+ 3;
104 catalog_filename
= new char[len
];
106 strncpy(catalog_filename
, LOCALEPATH
, lp
);
107 *(catalog_filename
+ lp
) = '/';
108 strncpy(catalog_filename
+ lp
+ 1, locale
, lc
);
109 *(catalog_filename
+ lp
+ lc
+ 1) = '/';
110 strncpy(catalog_filename
+ lp
+ lc
+ 2, catalog
, ct
+ 1);
113 catalog_fd
= catopen(catalog_filename
, MCLoadBySet
);
114 # else // !MCLoadBySet
115 catalog_fd
= catopen(catalog_filename
, NL_CAT_LOCALE
);
116 # endif // MCLoadBySet
118 if (catalog_fd
== (nl_catd
) -1)
119 fprintf(stderr
, "failed to open catalog, using default messages\n");
120 #else // !HAVE_CATOPEN
122 catalog_filename
= (char *) 0;
123 #endif // HAVE_CATOPEN
127 const char *I18n::getMessage(int set
, int msg
, const char *msgString
) const {
128 #if defined(NLS) && defined(HAVE_CATGETS)
129 if (catalog_fd
!= (nl_catd
) -1)
130 return (const char *) catgets(catalog_fd
, set
, msg
, msgString
);
This page took 0.044402 seconds and 4 git commands to generate.