mirror of https://github.com/ericonr/purr-c.git
Create loc_init() for localization initialization.
Avoids repetition; gemi and purr are now using it. Also use setlocale() unconditionally, since it's always good.
This commit is contained in:
parent
51d5882344
commit
80258a9a03
4
gemi.c
4
gemi.c
|
@ -48,9 +48,7 @@ int main(int argc, char **argv)
|
|||
bool debug = false, no_strip = false;
|
||||
int redirections = 0, redirections_pos = 0;
|
||||
|
||||
setlocale(LC_MESSAGES, "");
|
||||
bindtextdomain(GETTEXT_PACKAGE, GETTEXT_DIR);
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
loc_init();
|
||||
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "+bpsandhr:")) != -1) {
|
||||
|
|
4
purr.c
4
purr.c
|
@ -60,9 +60,7 @@ int main (int argc, char **argv)
|
|||
|
||||
bool send = false, recv = false;
|
||||
|
||||
setlocale(LC_MESSAGES, "");
|
||||
bindtextdomain(GETTEXT_PACKAGE, GETTEXT_DIR);
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
loc_init();
|
||||
|
||||
// check program name:
|
||||
// symlinks to original program with special behavior
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
#ifndef __TRANSLATION_H_
|
||||
#define __TRANSLATION_H_
|
||||
|
||||
#ifdef USE_LIBINTL
|
||||
|
||||
#include <locale.h>
|
||||
#include <libintl.h>
|
||||
#define _(a) gettext(a)
|
||||
|
||||
#ifndef GETTEXT_PACKAGE
|
||||
#define GETTEXT_PACKAGE NULL
|
||||
#endif /* GETTEXT_DOMAIN */
|
||||
|
||||
#ifndef GETTEXT_DIR
|
||||
#define GETTEXT_DIR NULL
|
||||
#endif /* GETTEXT_DIR */
|
||||
|
||||
#ifdef USE_LIBINTL
|
||||
# include <libintl.h>
|
||||
# define _(a) gettext(a)
|
||||
#else /* USE_LIBINTL */
|
||||
|
||||
#define _(a) a
|
||||
#define setlocale(a,b)
|
||||
#define bindtextdomain(a,b)
|
||||
#define textdomain(a)
|
||||
|
||||
# define _(a) a
|
||||
#endif /* USE_LIBINTL */
|
||||
|
||||
// use this only in main()
|
||||
static inline void loc_init(void)
|
||||
{
|
||||
// so libc understands utf8
|
||||
setlocale(LC_CTYPE, "");
|
||||
// so messages are localized
|
||||
setlocale(LC_MESSAGES, "");
|
||||
#ifdef USE_LIBINTL
|
||||
// to load my localization
|
||||
bindtextdomain(GETTEXT_PACKAGE, GETTEXT_DIR);
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __TRANSLATION_H_
|
||||
|
|
Loading…
Reference in New Issue