aboutsummaryrefslogtreecommitdiffhomepage
path: root/set_color.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-24 03:37:20 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-24 03:37:20 +1000
commit64fee9865ee85ada8660009b37fec556d6ce190b (patch)
treeb97da393c64d1239b39001869849900de0cd2ef4 /set_color.c
parent89eb80f3a417897cc533746f3811458d0cbb291f (diff)
Add gettext i18n support for the set_color command
darcs-hash:20060123173720-ac50b-3e7621d28d041042c3bf7424a8210013d7c72b29.gz
Diffstat (limited to 'set_color.c')
-rw-r--r--set_color.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/set_color.c b/set_color.c
index 0e723a02..977b2b25 100644
--- a/set_color.c
+++ b/set_color.c
@@ -7,6 +7,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <locale.h>
#if HAVE_NCURSES_H
#include <ncurses.h>
@@ -30,6 +31,10 @@
#include <getopt.h>
#endif
+#if HAVE_LIBINTL_H
+#include <libintl.h>
+#endif
+
/*
Small utility for setting the color.
Usage: set_color COLOR
@@ -38,6 +43,17 @@
#define COLORS (sizeof(col)/sizeof(char *))
+/**
+ Program name
+*/
+#define SET_COLOR "set_color"
+
+#if HAVE_GETTEXT
+#define _(string) gettext(string)
+#else
+#define _(string) (string)
+#endif
+
char *col[]=
{
"black",
@@ -109,12 +125,25 @@ void print_colors()
}
}
+static void locale_init()
+{
+ setlocale( LC_ALL, "" );
+#if HAVE_GETTEXT
+ bindtextdomain( PACKAGE_NAME, LOCALEDIR );
+ textdomain( PACKAGE_NAME );
+#endif
+}
+
+
int main( int argc, char **argv )
{
char *bgcolor=0;
char *fgcolor=0;
int fg, bg;
int bold=0;
+
+ locale_init();
+
while( 1 )
{
@@ -180,7 +209,7 @@ int main( int argc, char **argv )
break;
case 'v':
- fprintf( stderr, "set_color, version %s\n", PACKAGE_VERSION );
+ fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION );
exit( 0 );
case 'c':
@@ -206,13 +235,13 @@ int main( int argc, char **argv )
break;
default:
- printf( "set_color: Too many arguments\n" );
+ printf( _("%s: Too many arguments\n"), SET_COLOR );
return 1;
}
if( !fgcolor && !bgcolor && !bold )
{
- fprintf( stderr, "set_color: Expected an argument\n" );
+ fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR );
print_help();
return 1;
}
@@ -220,14 +249,14 @@ int main( int argc, char **argv )
fg = translate_color(fgcolor);
if( fgcolor && (fg==-1))
{
- fprintf( stderr, "set_color: Unknown color %s\n", fgcolor );
+ fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, fgcolor );
return 1;
}
bg = translate_color(bgcolor);
if( bgcolor && (bg==-1))
{
- fprintf( stderr, "set_color: Unknown color %s\n", bgcolor );
+ fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, bgcolor );
return 1;
}