[w3m-dev 04308] Support message i18n with w3m

Takao Fujiwara - Tokyo S/W Center <[email protected]> Sat, 14 Jun 2008 00:40:59 +0900
Newsgroups gmane.comp.web.w3m.devel
Organization Sun Microsystems
Message-ID <[email protected]>

I found the visible message strings "Viewing" and "Do you want to exit w3m? (y/n)" and --help are not localized.

Currently w3m doesn't show multibyte chars on UTF-8 locales and I added bind_textdomain_codeset() and wc_conv_from_utf8() so that w3m can works with
all locales.
The attached patch works fine with me. Could you review it?

If you would think the encoding of ja.po is UTF-8, It would be nice for my engineerings and other language communities might be involved.

Thanks,
fujiwara



--- w3m/display.c.orig	2008-06-14 00:07:41.548122000 +0900
+++ w3m/display.c	2008-06-14 00:08:45.791547000 +0900
@@ -1,6 +1,7 @@
 /* $Id: display.c,v 1.70 2007/05/29 12:07:02 inu Exp $ */
 #include <signal.h>
 #include "fm.h"
+#include "utf8.h"
 
 /* *INDENT-OFF* */
 #ifdef USE_COLOR
@@ -289,6 +290,8 @@ static Str
 make_lastline_message(Buffer *buf)
 {
     Str msg, s = NULL;
+    Str utf8_str = NULL;
+    Str wtf_str = NULL;
     int sl = 0;
 
     if (displayLink) {
@@ -330,9 +333,12 @@ make_lastline_message(Buffer *buf)
 	int r = (int)((double)cl * 100.0 / (double)(ll ? ll : 1) + 0.5);
 	Strcat(msg, Sprintf("%d/%d (%d%%)", cl, ll, r));
     }
-    else
-	/* FIXME: gettextize? */
-	Strcat_charp(msg, "Viewing");
+    else {
+	utf8_str = Strnew_charp (_("Viewing"));
+	wtf_str = wc_conv_from_utf8 (utf8_str, InnerCharset);
+	Strcat_charp(msg, wtf_str->ptr);
+	Strfree (utf8_str);
+    }
 #ifdef USE_SSL
     if (buf->ssl_certificate)
 	Strcat_charp(msg, "[SSL]");
--- w3m/file.c.orig	2008-06-14 00:07:47.905254000 +0900
+++ w3m/file.c	2008-06-14 00:08:45.815447000 +0900
@@ -18,6 +18,7 @@
 #include "parsetagx.h"
 #include "local.h"
 #include "regex.h"
+#include "utf8.h"
 
 #ifndef max
 #define max(a,b)        ((a) > (b) ? (a) : (b))
@@ -1512,6 +1513,8 @@ getAuthCookie(struct http_auth *hauth, c
 {
     Str ss = NULL;
     Str tmp;
+    Str utf8_str = NULL;
+    Str wtf_str = NULL;
     TextListItem *i;
     int a_found;
     int auth_header_len = strlen(auth_header);
@@ -1538,7 +1541,10 @@ getAuthCookie(struct http_auth *hauth, c
 	 * Authorization: header is sent to the server. 
 	 */
 	if (fmInitialized) {
-	    message("Wrong username or password", 0, 0);
+	    utf8_str = Strnew_charp (_("Wrong username or password"));
+	    wtf_str = wc_conv_from_utf8 (utf8_str, InnerCharset);
+	    message(wtf_str->ptr, 0, 0);
+	    Strfree (utf8_str);
 	    refresh();
 	}
 	else
@@ -1563,12 +1569,12 @@ getAuthCookie(struct http_auth *hauth, c
 	if (fmInitialized) {
 	    char *pp;
 	    term_raw();
-	    /* FIXME: gettextize? */
-	    if ((pp = inputStr(Sprintf("Username for %s: ", realm)->ptr,
-			       NULL)) == NULL)
+	    if ((pp = inputStr(Sprintf(_("Username for %s: "), realm)->ptr,
+			       NULL)) == NULL) {
 		return;
+	    }
 	    *uname = Str_conv_to_system(Strnew_charp(pp));
-	    if ((pp = inputLine(Sprintf("Password for %s: ", realm)->ptr, NULL,
+	    if ((pp = inputLine(Sprintf(_("Password for %s: "), realm)->ptr, NULL,
 				IN_PASSWORD)) == NULL) {
 		*uname = NULL;
 		return;
--- w3m/linein.c.orig	2008-06-14 00:07:54.134302000 +0900
+++ w3m/linein.c	2008-06-14 00:08:45.827975000 +0900
@@ -2,6 +2,7 @@
 #include "fm.h"
 #include "local.h"
 #include "myctype.h"
+#include "utf8.h"
 
 #ifdef USE_MOUSE
 #ifdef USE_GPM
@@ -90,6 +91,8 @@ inputLineHistSearch(char *prompt, char *
     char *p;
 #ifdef USE_M17N
     Str tmp;
+    Str utf8_str = NULL;
+    Str wtf_str = NULL;
 #endif
 
     is_passwd = FALSE;
@@ -164,7 +167,10 @@ inputLineHistSearch(char *prompt, char *
 		offset = 0;
 	}
 	move(LASTLINE, 0);
-	addstr(prompt);
+	utf8_str = Strnew_charp (prompt);
+	wtf_str = wc_conv_from_utf8 (utf8_str, InnerCharset);
+	addstr (wtf_str->ptr);
+	Strfree (utf8_str);
 	if (is_passwd)
 	    addPasswd(strBuf->ptr, strProp, CLen, offset, COLS - opos);
 	else
--- w3m/main.c.orig	2007-06-04 22:21:10.000000000 +0900
+++ w3m/main.c	2008-06-14 00:08:45.847434000 +0900
@@ -11,6 +11,9 @@
 #include <sys/wait.h>
 #endif
 #include <time.h>
+#if defined(HAVE_LANGINFO_CODESET)
+#include <langinfo.h>
+#endif
 #include "terms.h"
 #include "myctype.h"
 #include "regex.h"
@@ -185,82 +188,93 @@ fversion(FILE * f)
 static void
 fusage(FILE * f, int err)
 {
+    char *codeset = NULL;
+
+#if defined(HAVE_LANGINFO_CODESET)
+    codeset = bind_textdomain_codeset (PACKAGE, NULL);
+    bind_textdomain_codeset (PACKAGE, nl_langinfo (CODESET));
+#endif
+
     fversion(f);
-    /* FIXME: gettextize? */
-    fprintf(f, "usage: w3m [options] [URL or filename]\noptions:\n");
-    fprintf(f, "    -t tab           set tab width\n");
-    fprintf(f, "    -r               ignore backspace effect\n");
-    fprintf(f, "    -l line          # of preserved line (default 10000)\n");
+    fprintf(f, _("usage: w3m [options] [URL or filename]\noptions:\n"));
+    fprintf(f, _("    -t tab           set tab width\n"));
+    fprintf(f, _("    -r               ignore backspace effect\n"));
+    fprintf(f, _("    -l line          # of preserved line (default 10000)\n"));
 #ifdef USE_M17N
-    fprintf(f, "    -I charset       document charset\n");
-    fprintf(f, "    -O charset       display/output charset\n");
+    fprintf(f, _("    -I charset       document charset\n"));
+    fprintf(f, _("    -O charset       display/output charset\n"));
 #ifndef DEBIAN			/* disabled by ukai: -s is used for squeeze multi lines */
-    fprintf(f, "    -e               EUC-JP\n");
-    fprintf(f, "    -s               Shift_JIS\n");
-    fprintf(f, "    -j               JIS\n");
+    fprintf(f, _("    -e               EUC-JP\n"));
+    fprintf(f, _("    -s               Shift_JIS\n"));
+    fprintf(f, _("    -j               JIS\n"));
 #endif
 #endif
-    fprintf(f, "    -B               load bookmark\n");
-    fprintf(f, "    -bookmark file   specify bookmark file\n");
-    fprintf(f, "    -T type          specify content-type\n");
-    fprintf(f, "    -m               internet message mode\n");
-    fprintf(f, "    -v               visual startup mode\n");
+    fprintf(f, _("    -B               load bookmark\n"));
+    fprintf(f, _("    -bookmark file   specify bookmark file\n"));
+    fprintf(f, _("    -T type          specify content-type\n"));
+    fprintf(f, _("    -m               internet message mode\n"));
+    fprintf(f, _("    -v               visual startup mode\n"));
 #ifdef USE_COLOR
-    fprintf(f, "    -M               monochrome display\n");
+    fprintf(f, _("    -M               monochrome display\n"));
 #endif				/* USE_COLOR */
     fprintf(f,
-	    "    -N               open URL of command line on each new tab\n");
-    fprintf(f, "    -F               automatically render frame\n");
+	    _("    -N               open URL of command line on each new tab\n"));
+    fprintf(f, _("    -F               automatically render frame\n"));
     fprintf(f,
-	    "    -cols width      specify column width (used with -dump)\n");
+	    _("    -cols width      specify column width (used with -dump)\n"));
     fprintf(f,
-	    "    -ppc count       specify the number of pixels per character (4.0...32.0)\n");
+	    _("    -ppc count       specify the number of pixels per character (4.0...32.0)\n"));
 #ifdef USE_IMAGE
     fprintf(f,
-	    "    -ppl count       specify the number of pixels per line (4.0...64.0)\n");
+	    _("    -ppl count       specify the number of pixels per line (4.0...64.0)\n"));
 #endif
-    fprintf(f, "    -dump            dump formatted page into stdout\n");
+    fprintf(f, _("    -dump            dump formatted page into stdout\n"));
     fprintf(f,
-	    "    -dump_head       dump response of HEAD request into stdout\n");
-    fprintf(f, "    -dump_source     dump page source into stdout\n");
-    fprintf(f, "    -dump_both       dump HEAD and source into stdout\n");
+	    _("    -dump_head       dump response of HEAD request into stdout\n"));
+    fprintf(f, _("    -dump_source     dump page source into stdout\n"));
+    fprintf(f, _("    -dump_both       dump HEAD and source into stdout\n"));
     fprintf(f,
-	    "    -dump_extra      dump HEAD, source, and extra information into stdout\n");
-    fprintf(f, "    -post file       use POST method with file content\n");
-    fprintf(f, "    -header string   insert string as a header\n");
-    fprintf(f, "    +<num>           goto <num> line\n");
-    fprintf(f, "    -num             show line number\n");
-    fprintf(f, "    -no-proxy        don't use proxy\n");
+	    _("    -dump_extra      dump HEAD, source, and extra information into stdout\n"));
+    fprintf(f, _("    -post file       use POST method with file content\n"));
+    fprintf(f, _("    -header string   insert string as a header\n"));
+    fprintf(f, _("    +<num>           goto <num> line\n"));
+    fprintf(f, _("    -num             show line number\n"));
+    fprintf(f, _("    -no-proxy        don't use proxy\n"));
 #ifdef INET6
-    fprintf(f, "    -4               IPv4 only (-o dns_order=4)\n");
-    fprintf(f, "    -6               IPv6 only (-o dns_order=6)\n");
+    fprintf(f, _("    -4               IPv4 only (-o dns_order=4)\n"));
+    fprintf(f, _("    -6               IPv6 only (-o dns_order=6)\n"));
 #endif
 #ifdef USE_MOUSE
-    fprintf(f, "    -no-mouse        don't use mouse\n");
+    fprintf(f, _("    -no-mouse        don't use mouse\n"));
 #endif				/* USE_MOUSE */
 #ifdef USE_COOKIE
     fprintf(f,
-	    "    -cookie          use cookie (-no-cookie: don't use cookie)\n");
+	    _("    -cookie          use cookie (-no-cookie: don't use cookie)\n"));
 #endif				/* USE_COOKIE */
-    fprintf(f, "    -pauth user:pass proxy authentication\n");
-    fprintf(f, "    -graph           use graphic character\n");
-    fprintf(f, "    -no-graph        don't use graphic character\n");
+    fprintf(f, _("    -pauth user:pass proxy authentication\n"));
+    fprintf(f, _("    -graph           use graphic character\n"));
+    fprintf(f, _("    -no-graph        don't use graphic character\n"));
 #ifdef DEBIAN			/* replaced by ukai: pager requires -s */
-    fprintf(f, "    -s               squeeze multiple blank lines\n");
+    fprintf(f, _("    -s               squeeze multiple blank lines\n"));
 #else
-    fprintf(f, "    -S               squeeze multiple blank lines\n");
+    fprintf(f, _("    -S               squeeze multiple blank lines\n"));
 #endif
-    fprintf(f, "    -W               toggle wrap search mode\n");
-    fprintf(f, "    -X               don't use termcap init/deinit\n");
+    fprintf(f, _("    -W               toggle wrap search mode\n"));
+    fprintf(f, _("    -X               don't use termcap init/deinit\n"));
     fprintf(f,
-	    "    -title[=TERM]    set buffer name to terminal title string\n");
-    fprintf(f, "    -o opt=value     assign value to config option\n");
-    fprintf(f, "    -show-option     print all config options\n");
-    fprintf(f, "    -config file     specify config file\n");
-    fprintf(f, "    -help            print this usage message\n");
-    fprintf(f, "    -version         print w3m version\n");
-    fprintf(f, "    -reqlog          write request logfile\n");
-    fprintf(f, "    -debug           DO NOT USE\n");
+	    _("    -title[=TERM]    set buffer name to terminal title string\n"));
+    fprintf(f, _("    -o opt=value     assign value to config option\n"));
+    fprintf(f, _("    -show-option     print all config options\n"));
+    fprintf(f, _("    -config file     specify config file\n"));
+    fprintf(f, _("    -help            print this usage message\n"));
+    fprintf(f, _("    -version         print w3m version\n"));
+    fprintf(f, _("    -reqlog          write request logfile\n"));
+    fprintf(f, _("    -debug           DO NOT USE\n"));
+
+#if defined(HAVE_LANGINFO_CODESET)
+    bind_textdomain_codeset (PACKAGE, codeset);
+#endif
+
     if (show_params_p)
 	show_params(f);
     exit(err);
@@ -398,6 +412,7 @@ main(int argc, char **argv, char **envp)
 #endif
 #ifdef ENABLE_NLS
     bindtextdomain(PACKAGE, LOCALEDIR);
+    bind_textdomain_codeset (PACKAGE, "UTF-8");
     textdomain(PACKAGE);
 #endif
 
@@ -2386,12 +2401,12 @@ _quitfm(int confirm)
     char *ans = "y";
 
     if (checkDownloadList())
-	/* FIXME: gettextize? */
-	ans = inputChar("Download process retains. "
-			"Do you want to exit w3m? (y/n)");
+	/* Translators: (y/n) should be ASCII. */
+	ans = inputChar(_("Download process retains. "
+			"Do you want to exit w3m? (y/n)"));
     else if (confirm)
-	/* FIXME: gettextize? */
-	ans = inputChar("Do you want to exit w3m? (y/n)");
+	/* Translators: (y/n) should be ASCII. */
+	ans = inputChar(_("Do you want to exit w3m? (y/n)"));
     if (!(ans && TOLOWER(*ans) == 'y')) {
 	displayBuffer(Currentbuf, B_NORMAL);
 	return;
--- w3m/po/POTFILES.in.orig	2008-06-14 00:08:21.554413000 +0900
+++ w3m/po/POTFILES.in	2008-06-14 00:08:45.849466000 +0900
@@ -1,9 +1,10 @@
 # List of source files containing translatable strings.
 # Copyright (C) 2003 Fumitoshi UKAI
-#main.c
+display.c
+file.c
+main.c
 menu.c
 rc.c
+url.c
 #w3mbookmark.c
 #w3mhelperpanel.c
-
-
--- w3m/url.c.orig	2008-06-14 00:08:27.957653000 +0900
+++ w3m/url.c	2008-06-14 00:08:45.860558000 +0900
@@ -23,6 +23,7 @@
 #include "Str.h"
 #include "myctype.h"
 #include "regex.h"
+#include "utf8.h"
 
 #ifdef USE_SSL
 #ifndef SSLEAY_VERSION_NUMBER
@@ -449,6 +450,8 @@ openSocket(char *const hostname,
 	   char *remoteport_name, unsigned short remoteport_num)
 {
     volatile int sock = -1;
+    Str utf8_str = NULL;
+    Str wtf_str = NULL;
 #ifdef INET6
     int *af;
     struct addrinfo hints, *res0, *res;
@@ -465,8 +468,10 @@ openSocket(char *const hostname,
     MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
 
     if (fmInitialized) {
-	/* FIXME: gettextize? */
-	message(Sprintf("Opening socket...")->ptr, 0, 0);
+	utf8_str = Strnew_charp (_("Opening socket..."));
+	wtf_str = wc_conv_from_utf8 (utf8_str, InnerCharset);
+	message(wtf_str->ptr, 0, 0);
+	Strfree (utf8_str);
 	refresh();
     }
     if (SETJMP(AbortLoading) != 0) {