wmitime: Improve locale support.
Previously, wmitime only had support for English, French, and (in Debian only) Hungarian. In addition, the choice was made at compile time. This patch adds run-time support for any language using the Latin alphabet. The locale is determined by the user's environment or may be specified on the command line with the "-l" option. Note that users whose environment specifies a non-Latin locale may wish to use, e.g., "-l C", as otherwise no date will appear. Note that, for simplicity, the month and day are now displayed as "01 JAN" as opposed to "JAN 01". (Previously, the former format was used for English and the latter for French.)
This commit is contained in:
		
							parent
							
								
									0fbe3d839a
								
							
						
					
					
						commit
						cc801880a5
					
				
					 4 changed files with 42 additions and 91 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
#LANG = fr
 | 
			
		||||
LIBS   = -lXpm -lXext -lX11 -lm
 | 
			
		||||
CFLAGS = -O2 -Wall
 | 
			
		||||
OBJS =	wmitime.o \
 | 
			
		||||
| 
						 | 
				
			
			@ -10,7 +9,7 @@ PREFIX = /usr/local
 | 
			
		|||
BINDIR = $(PREFIX)/bin
 | 
			
		||||
 | 
			
		||||
.c.o:
 | 
			
		||||
	$(CC) $(CPPFLAGS) $(CFLAGS) -D$(LANG) -c $< -o $*.o
 | 
			
		||||
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $*.o
 | 
			
		||||
 | 
			
		||||
wmitime: $(OBJS)
 | 
			
		||||
	$(CC) $(LDFLAGS) -o wmitime $^ $(LIBS)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +0,0 @@
 | 
			
		|||
// french.h
 | 
			
		||||
// Created by Pierre-Marie.Allemand@capway.com
 | 
			
		||||
// 08-jan-1999
 | 
			
		||||
 | 
			
		||||
static char daynames[7][3] =
 | 
			
		||||
{
 | 
			
		||||
    {"Di"},
 | 
			
		||||
    {"Lu"},
 | 
			
		||||
    {"Ma"},
 | 
			
		||||
    {"Me"},
 | 
			
		||||
    {"Je"},
 | 
			
		||||
    {"Ve"},
 | 
			
		||||
    {"Sa"}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static char monthnames[12][4] =
 | 
			
		||||
{
 | 
			
		||||
    {"Jan"},
 | 
			
		||||
    {"Fev"},
 | 
			
		||||
    {"Mar"},
 | 
			
		||||
    {"Avr"},
 | 
			
		||||
    {"Mai"},
 | 
			
		||||
    {"Jun"},
 | 
			
		||||
    {"Jui"},
 | 
			
		||||
    {"Aou"},
 | 
			
		||||
    {"Sep"},
 | 
			
		||||
    {"Oct"},
 | 
			
		||||
    {"Nov"},
 | 
			
		||||
    {"Dec"}
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -1,35 +0,0 @@
 | 
			
		|||
// language.h
 | 
			
		||||
 | 
			
		||||
static char daynames[7][3] =
 | 
			
		||||
{
 | 
			
		||||
    {"Su"},
 | 
			
		||||
    {"Mo"},
 | 
			
		||||
    {"Tu"},
 | 
			
		||||
    {"We"},
 | 
			
		||||
    {"Th"},
 | 
			
		||||
    {"Fr"},
 | 
			
		||||
    {"Sa"}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static char monthnames[12][4] =
 | 
			
		||||
{
 | 
			
		||||
    {"Jan"},
 | 
			
		||||
    {"Feb"},
 | 
			
		||||
    {"Mar"},
 | 
			
		||||
    {"Apr"},
 | 
			
		||||
    {"May"},
 | 
			
		||||
    {"Jun"},
 | 
			
		||||
    {"Jul"},
 | 
			
		||||
    {"Aug"},
 | 
			
		||||
    {"Sep"},
 | 
			
		||||
    {"Oct"},
 | 
			
		||||
    {"Nov"},
 | 
			
		||||
    {"Dec"}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +16,9 @@
 | 
			
		|||
#include <unistd.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <locale.h>
 | 
			
		||||
#include <langinfo.h>
 | 
			
		||||
#include <iconv.h>
 | 
			
		||||
 | 
			
		||||
#include <sys/wait.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -31,16 +34,6 @@
 | 
			
		|||
#include "wmgeneral/wmgeneral.h"
 | 
			
		||||
#include "wmgeneral/misc.h"
 | 
			
		||||
 | 
			
		||||
#ifdef fr_FR
 | 
			
		||||
#define fr
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef fr
 | 
			
		||||
#include "french.h"
 | 
			
		||||
#else
 | 
			
		||||
#include "language.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "wmitime-master.xpm"
 | 
			
		||||
char wmitime_mask_bits[64*64];
 | 
			
		||||
int  wmitime_mask_width = 64;
 | 
			
		||||
| 
						 | 
				
			
			@ -61,6 +54,7 @@ extern	char **environ;
 | 
			
		|||
char	*ProgName;
 | 
			
		||||
 | 
			
		||||
char uconfig_file[256];
 | 
			
		||||
char locale[256];
 | 
			
		||||
 | 
			
		||||
time_t		curtime;
 | 
			
		||||
time_t		prevtime;
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +89,7 @@ int main(int argc, char *argv[]) {
 | 
			
		|||
	int		i;
 | 
			
		||||
 | 
			
		||||
    uconfig_file[0] = 0;
 | 
			
		||||
    locale[0] = 0;
 | 
			
		||||
 | 
			
		||||
	/* Parse Command Line */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -137,6 +132,13 @@ int main(int argc, char *argv[]) {
 | 
			
		|||
                    TwelveHour = 1;
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case 'l' :
 | 
			
		||||
                if (argc > (i+1))
 | 
			
		||||
                {
 | 
			
		||||
                    strcpy(locale, argv[i+1]);
 | 
			
		||||
                    i++;
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
				usage();
 | 
			
		||||
				exit(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -145,6 +147,11 @@ int main(int argc, char *argv[]) {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (setlocale(LC_ALL, locale) == NULL)
 | 
			
		||||
	    fprintf(stderr,
 | 
			
		||||
		    "warning: locale '%s' not recognized; defaulting to '%s'.",
 | 
			
		||||
		    locale, setlocale(LC_ALL, NULL));
 | 
			
		||||
 | 
			
		||||
	wmitime_routine(argc, argv);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -365,28 +372,37 @@ void DrawStdTime(void)
 | 
			
		|||
 | 
			
		||||
void DrawDate(void)
 | 
			
		||||
{
 | 
			
		||||
    char BlitStr[20];
 | 
			
		||||
    char OrigBlitStr[20], BlitStr[20];
 | 
			
		||||
    char *inbuf, *outbuf;
 | 
			
		||||
    size_t inbytesleft, outbytesleft;
 | 
			
		||||
    iconv_t cd;
 | 
			
		||||
 | 
			
		||||
    sprintf(BlitStr, "%s", daynames[clk->tm_wday]);
 | 
			
		||||
    cd = iconv_open("ASCII//TRANSLIT", nl_langinfo(CODESET));
 | 
			
		||||
 | 
			
		||||
    inbuf = OrigBlitStr;
 | 
			
		||||
    outbuf = BlitStr;
 | 
			
		||||
    inbytesleft = sizeof OrigBlitStr;
 | 
			
		||||
    outbytesleft = sizeof BlitStr;
 | 
			
		||||
 | 
			
		||||
    sprintf(OrigBlitStr, "%s", nl_langinfo(ABDAY_1 + clk->tm_wday));
 | 
			
		||||
    iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
 | 
			
		||||
    BlitStr[2] = 0;
 | 
			
		||||
    BlitString( BlitStr, 6, 50);
 | 
			
		||||
 | 
			
		||||
#ifdef fr
 | 
			
		||||
    inbuf = OrigBlitStr;
 | 
			
		||||
    outbuf = BlitStr;
 | 
			
		||||
    inbytesleft = sizeof OrigBlitStr;
 | 
			
		||||
    outbytesleft = sizeof BlitStr;
 | 
			
		||||
 | 
			
		||||
    // French date model
 | 
			
		||||
    sprintf(BlitStr, "%s", monthnames[clk->tm_mon]);
 | 
			
		||||
    sprintf(OrigBlitStr, "%s", nl_langinfo(ABMON_1 + clk->tm_mon));
 | 
			
		||||
    iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
 | 
			
		||||
    BlitStr[3] = 0;
 | 
			
		||||
    BlitString( BlitStr, 40, 50);
 | 
			
		||||
 | 
			
		||||
    sprintf(BlitStr, "%02i", clk->tm_mday);
 | 
			
		||||
    BlitString( BlitStr, 25, 50);
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
    sprintf(BlitStr, "%s", monthnames[clk->tm_mon]);
 | 
			
		||||
    BlitString( BlitStr, 25, 50);
 | 
			
		||||
    iconv_close(cd);
 | 
			
		||||
 | 
			
		||||
    sprintf(BlitStr, "%02i", clk->tm_mday);
 | 
			
		||||
    BlitString( BlitStr, 45, 50);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
    BlitString( BlitStr, 25, 50);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DrawInetWheel(void)
 | 
			
		||||
| 
						 | 
				
			
			@ -706,6 +722,7 @@ void usage(void)
 | 
			
		|||
	fprintf(stderr, "    -display <display name>\n");
 | 
			
		||||
	fprintf(stderr, "    -geometry +XPOS+YPOS      initial window position\n");
 | 
			
		||||
//    fprintf(stderr, "    -c <filename>             use specified config file\n");
 | 
			
		||||
	fprintf(stderr, "    -l <locale>               specify locale\n");
 | 
			
		||||
    fprintf(stderr, "    -h                        this help screen\n");
 | 
			
		||||
	fprintf(stderr, "    -v                        print the version number\n");
 | 
			
		||||
    fprintf(stderr, "\n");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue