[w3m-dev 04147] NLS for w3mbookmark / w3mhelperpanel

WATANABE Katsuyuki <[email protected]> Tue, 15 Mar 2005 01:49:11 +0900
Newsgroups gmane.comp.web.w3m.devel
Message-ID <[email protected]>
$BEOn5$G$9!#(B

$B;D$C$F$$$?(B w3mbookmark $B$H(B w3mhelperpanel $B$N(B NLS $B2=%Q%C%A$G$9!#(B

w3m $BK\BN$+$i$O(B charset $B$H(B locale $B$rEO$7!"%m!<%+%i%$%:$7$?J8;zNs$r(B
$B<hF@$9$k$N$O3F!9$G$d$k$h$&$K$7$F$_$^$7$?!#(B


diff -ur -X ignore.lst w3m-1.946-1/fm.h w3m-1.946-nls-1/fm.h
--- w3m-1.946-1/fm.h	2004-07-16 07:14:59.000000000 +0900
+++ w3m-1.946-nls-1/fm.h	2005-03-14 12:37:42.843750000 +0900
@@ -1014,6 +1014,7 @@
 global char FollowLocale init(TRUE);
 global char UseContentCharset init(TRUE);
 global char SearchConv init(TRUE);
+global char *Locale init(NULL);
 #define Str_conv_from_system(x) wc_Str_conv((x), SystemCharset, InnerCharset)
 #define Str_conv_to_system(x) wc_Str_conv_strict((x), InnerCharset, SystemCharset)
 #define Str_conv_to_halfdump(x) (ExtHalfdump ? wc_Str_conv((x), InnerCharset, DisplayCharset) : (x))
diff -ur -X ignore.lst w3m-1.946-1/main.c w3m-1.946-nls-1/main.c
--- w3m-1.946-1/main.c	2005-03-14 10:08:04.984375000 +0900
+++ w3m-1.946-nls-1/main.c	2005-03-14 12:37:56.578125000 +0900
@@ -377,7 +377,6 @@
     char *post_file = NULL;
     Str err_msg;
 #ifdef USE_M17N
-    char *Locale = NULL;
     wc_uint8 auto_detect;
 #ifdef __EMX__
     wc_ces CodePage;
@@ -4123,6 +4122,9 @@
     tmp = Sprintf("mode=panel&cookie=%s&bmark=%s&url=%s&title=%s"
 #ifdef USE_M17N
 		    "&charset=%s"
+#if ENABLE_NLS
+		    "&locale=%s"
+#endif
 #endif
 		    ,
 		  (Str_form_quote(localCookie()))->ptr,
@@ -4133,10 +4135,14 @@
 		  (Str_form_quote(wc_conv_strict(Currentbuf->buffername,
 						 InnerCharset,
 						 BookmarkCharset)))->ptr,
-		  wc_ces_to_charset(BookmarkCharset));
+		  wc_ces_to_charset(BookmarkCharset)
+#if ENABLE_NLS
+		  , (Str_form_quote(Strnew_charp(Locale)))->ptr
+#endif
 #else
-		  (Str_form_quote(Strnew_charp(Currentbuf->buffername)))->ptr);
+		  (Str_form_quote(Strnew_charp(Currentbuf->buffername)))->ptr
 #endif
+	    );
     request = newFormList(NULL, "post", NULL, NULL, NULL, NULL, NULL);
     request->body = tmp->ptr;
     request->length = tmp->length;
diff -ur -X ignore.lst w3m-1.946-1/po/POTFILES.in w3m-1.946-nls-1/po/POTFILES.in
--- w3m-1.946-1/po/POTFILES.in	2003-09-25 03:35:06.000000000 +0900
+++ w3m-1.946-nls-1/po/POTFILES.in	2005-03-14 10:36:14.234375000 +0900
@@ -3,7 +3,6 @@
 #main.c
 menu.c
 rc.c
-#w3mbookmark.c
-#w3mhelperpanel.c
-
+w3mbookmark.c
+w3mhelperpanel.c
 
diff -ur -X ignore.lst w3m-1.946-1/po/ja.po w3m-1.946-nls-1/po/ja.po
--- w3m-1.946-1/po/ja.po	2004-07-16 07:15:00.000000000 +0900
+++ w3m-1.946-nls-1/po/ja.po	2005-03-14 10:36:14.250000000 +0900
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: w3m 0.5.1\n"
 "Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2004-07-14 15:51+0900\n"
+"POT-Creation-Date: 2005-03-14 00:44+0900\n"
 "PO-Revision-Date: 2003-09-26 03:35+0900\n"
 "Last-Translator: Fumitoshi UKAI <[email protected]>\n"
 "Language-Team: Japanese\n"
@@ -809,3 +809,43 @@
 #: rc.c:1150
 msgid "en;q=1.0"
 msgstr "ja;q=1.0, en;q=0.5"
+
+#: w3mbookmark.c:32
+msgid "Register to my bookmark"
+msgstr "$B%V%C%/%^!<%/$NEPO?(B"
+
+#: w3mbookmark.c:33
+msgid "ADD"
+msgstr "$BEPO?(B"
+
+#: w3mbookmark.c:34
+msgid "Miscellaneous"
+msgstr "$BL$J,N`(B"
+
+#: w3mhelperpanel.c:35
+msgid "External Viewers Setup"
+msgstr "$B30It%S%e!<%"$NJT=8(B"
+
+#: w3mhelperpanel.c:36
+msgid "New Entry"
+msgstr "$B?75,EPO?(B"
+
+#: w3mhelperpanel.c:37
+msgid "Type"
+msgstr "$B%G!<%?%?%$%W(B"
+
+#: w3mhelperpanel.c:38
+msgid "Command"
+msgstr "$B30It%3%^%s%I(B"
+
+#: w3mhelperpanel.c:39
+msgid "Register"
+msgstr "$BEPO?(B"
+
+#: w3mhelperpanel.c:40
+msgid "Delete"
+msgstr "$B:o=|(B"
+
+#: w3mhelperpanel.c:41
+msgid "Do it"
+msgstr "$B<B9T(B"
diff -ur -X ignore.lst w3m-1.946-1/po/w3m.pot w3m-1.946-nls-1/po/w3m.pot
--- w3m-1.946-1/po/w3m.pot	2004-07-16 07:15:00.000000000 +0900
+++ w3m-1.946-nls-1/po/w3m.pot	2005-03-14 10:36:14.296875000 +0900
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2004-07-14 15:51+0900\n"
+"POT-Creation-Date: 2005-03-14 00:44+0900\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <[email protected]>\n"
@@ -808,3 +808,43 @@
 #: rc.c:1150
 msgid "en;q=1.0"
 msgstr ""
+
+#: w3mbookmark.c:32
+msgid "Register to my bookmark"
+msgstr ""
+
+#: w3mbookmark.c:33
+msgid "ADD"
+msgstr ""
+
+#: w3mbookmark.c:34
+msgid "Miscellaneous"
+msgstr ""
+
+#: w3mhelperpanel.c:35
+msgid "External Viewers Setup"
+msgstr ""
+
+#: w3mhelperpanel.c:36
+msgid "New Entry"
+msgstr ""
+
+#: w3mhelperpanel.c:37
+msgid "Type"
+msgstr ""
+
+#: w3mhelperpanel.c:38
+msgid "Command"
+msgstr ""
+
+#: w3mhelperpanel.c:39
+msgid "Register"
+msgstr ""
+
+#: w3mhelperpanel.c:40
+msgid "Delete"
+msgstr ""
+
+#: w3mhelperpanel.c:41
+msgid "Do it"
+msgstr ""
diff -ur -X ignore.lst w3m-1.946-1/rc.c w3m-1.946-nls-1/rc.c
--- w3m-1.946-1/rc.c	2004-08-03 08:25:32.000000000 +0900
+++ w3m-1.946-nls-1/rc.c	2005-03-14 12:33:47.875000000 +0900
@@ -1246,8 +1246,12 @@
     "<html><head><title>Option Setting Panel</title></head><body>\
 <h1 align=center>Option Setting Panel<br>(w3m version %s)</b></h1>\
 <form method=post action=\"file:///$LIB/" W3MHELPERPANEL_CMDNAME "\">\
-<input type=hidden name=mode value=panel>\
-<input type=hidden name=cookie value=\"%s\">\
+<input type=hidden name=mode value=panel>\n"
+#ifdef ENABLE_NLS
+"<input type=hidden name=charset value=\"%s\">\n"
+"<input type=hidden name=locale value=\"%s\">\n"
+#endif
+"<input type=hidden name=cookie value=\"%s\">\
 <input type=submit value=\"%s\">\
 </form><br>\
 <form method=internal action=option>";
@@ -1303,6 +1307,10 @@
 
     if (optionpanel_str == NULL)
 	optionpanel_str = Sprintf(optionpanel_src1, w3m_version,
+#if ENABLE_NLS
+				wc_ces_to_charset(SystemCharset),
+				Locale,
+#endif
 			      html_quote(localCookie()->ptr), _(CMT_HELPER));
 #if ENABLE_NLS
     OptionCharset = SystemCharset;	/* FIXME */
diff -ur -X ignore.lst w3m-1.946-1/w3mbookmark.c w3m-1.946-nls-1/w3mbookmark.c
--- w3m-1.946-1/w3mbookmark.c	2004-07-16 07:14:59.000000000 +0900
+++ w3m-1.946-nls-1/w3mbookmark.c	2005-03-14 12:29:29.937500000 +0900
@@ -2,29 +2,44 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "config.h"
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if !HAVE_SETLOCALE
+#define setlocale(category, locale)	/* empty */
+#endif
+
+#if ENABLE_NLS
+#include <libintl.h>
+#define _(String) gettext (String)
+#define N_(String) (String)
+#else
+# undef bindtextdomain
+# define bindtextdomain(Domain, Directory)	/* empty */
+# undef textdomain
+# define textdomain(Domain)	/* empty */
+# define _(Text) Text
+# define N_(Text) Text
+# define gettext(Text) Text
+#endif
+
 #include "Str.h"
 #include "indep.h"
 #include "textlist.h"
 #include "parsetag.h"
 
-#if LANG == JA
-/* FIXME: gettextize here */
-#define BKMARK_TITLE "$B%V%C%/%^!<%/$NEPO?(B"
-#define BKMARK_ADD "$BEPO?(B"
-#define DEFAULT_SECTION "$BL$J,N`(B"
-#else
-#define BKMARK_TITLE "Register to my bookmark"
-#define BKMARK_ADD "ADD"
-#define DEFAULT_SECTION "Miscellaneous"
-#endif
+#define BKMARK_TITLE N_("Register to my bookmark")
+#define BKMARK_ADD N_("ADD")
+#define DEFAULT_SECTION N_("Miscellaneous")
 
 static char *bkmark_src1 =
     "<html>\n\
 <head>\n\
-<title>" BKMARK_TITLE "</title>\n\
+<title>%s</title>\n\
 </head>\n\
 <body>\n\
-<h1>" BKMARK_TITLE "</h1>\n\
+<h1>%s</h1>\n\
 <form method=post action=\"file:///$LIB/" W3MBOOKMARK_CMDNAME "\">\n\
 <input type=hidden name=mode value=register>\n\
 <input type=hidden name=bmark value=\"%s\">\n\
@@ -35,7 +50,7 @@
     "<tr><td>New&nbsp;Section:<td><input type=text name=newsection size=60>\n\
 <tr><td>URL:<td><input type=text name=url value=\"%s\" size=60>\n\
 <tr><td>Title:<td><input type=text name=title value=\"%s\" size=60>\n\
-<tr><td><input type=submit value=\"" BKMARK_ADD "\">\n\
+<tr><td><input type=submit value=\"%s\">\n\
 </table>\n\
 </form>\n\
 </body>\n\
@@ -58,13 +73,14 @@
     FILE *f;
     char *p;
 
-    if (charset == NULL) {
+    if (charset == NULL || *charset == '\0') {
 	printf("Content-Type: text/html\n\n");
     }
     else {
 	printf("Content-Type: text/html; charset=%s\n\n", charset);
     }
-    printf(bkmark_src1, html_quote(bmark), html_quote(Local_cookie));
+    printf(bkmark_src1, _(BKMARK_TITLE), _(BKMARK_TITLE), html_quote(bmark),
+		    html_quote(Local_cookie));
     if ((f = fopen(bmark, "r")) != NULL) {
 	printf("<tr><td>Section:<td><select name=\"section\">\n");
 	while (tmp = Strfgets(f), tmp->length > 0) {
@@ -80,7 +96,7 @@
 	}
 	printf("</select>\n");
     }
-    printf(bkmark_src2, html_quote(url), html_quote(title));
+    printf(bkmark_src2, html_quote(url), html_quote(title), _(BKMARK_ADD));
 }
 
 /* create new bookmark */
@@ -122,7 +138,7 @@
     if (section == NULL || *section == '\0')
 	section = tag_get_value(data, "section");
     if (section == NULL || *section == '\0')
-	section = DEFAULT_SECTION;
+	section = _(DEFAULT_SECTION);
 
     if (url == NULL || *url == '\0' || title == NULL || *title == '\0') {
 	/* Bookmark not added */
@@ -189,6 +205,9 @@
     char *url;
     char *title;
     char *charset;
+#if ENABLE_NLS
+    char *locale;
+#endif
     char *sent_cookie;
 
     p = getenv("REQUEST_METHOD");
@@ -226,6 +245,15 @@
     url = tag_get_value(cgiarg, "url");
     title = tag_get_value(cgiarg, "title");
     charset = tag_get_value(cgiarg, "charset");
+#if ENABLE_NLS
+    locale = tag_get_value(cgiarg, "locale");
+    if (locale == NULL)
+	locale = "";
+    setlocale(LC_ALL, locale);
+    bindtextdomain(PACKAGE, LOCALEDIR);
+    textdomain(PACKAGE);
+#endif
+
     if (bmark == NULL || url == NULL)
 	goto request_err;
     if (mode && !strcmp(mode, "panel")) {
diff -ur -X ignore.lst w3m-1.946-1/w3mhelperpanel.c w3m-1.946-nls-1/w3mhelperpanel.c
--- w3m-1.946-1/w3mhelperpanel.c	2003-09-24 03:42:25.000000000 +0900
+++ w3m-1.946-nls-1/w3mhelperpanel.c	2005-03-14 12:35:12.250000000 +0900
@@ -4,30 +4,41 @@
 #include <stdio.h>
 #include <string.h>
 #include "config.h"
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if !HAVE_SETLOCALE
+#define setlocale(category, locale)	/* empty */
+#endif
+
+#if ENABLE_NLS
+#include <libintl.h>
+#define _(String) gettext (String)
+#define N_(String) (String)
+#else
+# undef bindtextdomain
+# define bindtextdomain(Domain, Directory)	/* empty */
+# undef textdomain
+# define textdomain(Domain)	/* empty */
+# define _(Text) Text
+# define N_(Text) Text
+# define gettext(Text) Text
+#endif
+
 #include "Str.h"
 #include "indep.h"
 #include "textlist.h"
 #include "parsetag.h"
 #include "myctype.h"
 
-#if LANG == JA
-/* FIXME: gettextize here */
-#define MSG_TITLE		"$B30It%S%e!<%"$NJT=8(B"
-#define MSG_NEW_ENTRY		"$B?75,EPO?(B"
-#define MSG_TYPE		"$B%G!<%?%?%$%W(B"
-#define MSG_COMMAND		"$B30It%3%^%s%I(B"
-#define MSG_REGISTER		"$BEPO?(B"
-#define MSG_DELETE		"$B:o=|(B"
-#define MSG_DOIT		"$B<B9T(B"
-#else				/* LANG != JA */
-#define MSG_TITLE		"External Viewers Setup"
-#define MSG_NEW_ENTRY		"New Entry"
-#define MSG_TYPE		"Type"
-#define MSG_COMMAND		"Command"
-#define MSG_REGISTER		"Register"
-#define MSG_DELETE		"Delete"
-#define MSG_DOIT		"Do it"
-#endif				/* LANG != JA */
+#define MSG_TITLE		N_("External Viewers Setup")
+#define MSG_NEW_ENTRY		N_("New Entry")
+#define MSG_TYPE		N_("Type")
+#define MSG_COMMAND		N_("Command")
+#define MSG_REGISTER		N_("Register")
+#define MSG_DELETE		N_("Delete")
+#define MSG_DOIT		N_("Do it")
 
 char *local_cookie;
 
@@ -57,7 +68,7 @@
 }
 
 void
-printMailcapPanel(char *mailcap)
+printMailcapPanel(char *mailcap, char *charset)
 {
     FILE *f;
     Str tmp;
@@ -82,14 +93,14 @@
 	    }
 	}
     }
-#if LANG == JA
-    /* FIXME: gettextize here */
-    printf("Content-Type: text/html; charset=EUC-JP\n\n");
-#else
-    printf("Content-Type: text/html\n\n");
-#endif
+    if (charset == NULL || *charset == '\0') {
+	printf("Content-Type: text/html\n\n");
+    }
+    else {
+	printf("Content-Type: text/html; charset=%s\n\n", charset);
+    }
     printf("<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n<h1>%s</h1>\n",
-	   MSG_TITLE, MSG_TITLE);
+	   _(MSG_TITLE), _(MSG_TITLE));
     printf("<form method=post action=\"file:///$LIB/" W3MHELPERPANEL_CMDNAME
 	   "\">\n");
     printf("<input type=hidden name=mode value=edit>\n");
@@ -98,10 +109,10 @@
     printf("<table>\n<tr><td>%s:<td>%s=<input type=text name=newtype size=40>\n\
 <tr><td><td>%s=<input type=text name=newcmd size=40>\n\
 <tr><td><input type=submit name=submit value=\"%s\">\n</table>\n",
-	   MSG_NEW_ENTRY, MSG_TYPE, MSG_COMMAND, MSG_REGISTER);
+	   _(MSG_NEW_ENTRY), _(MSG_TYPE), _(MSG_COMMAND), _(MSG_REGISTER));
     printf("<p><hr width=50%%><p>\n<table border='0' cellpadding='0'>\n\
 <tr><th align=left><b>%s</b><th><b>%s</b>\n",
-	   MSG_TYPE, MSG_COMMAND);
+	   _(MSG_TYPE), _(MSG_COMMAND));
     while (tmp = Strfgets(f), tmp->length > 0) {
 	if (tmp->ptr[0] == '#')
 	    continue;
@@ -110,11 +121,11 @@
 	printf("<tr valign=top><td>%s<td>%s<td nowrap>", html_quote(type),
 	       html_quote(viewer));
 	printf("<input type=checkbox name=delete value=\"%s\">%s\n",
-	       html_quote(type), MSG_DELETE);
+	       html_quote(type), _(MSG_DELETE));
     }
     printf("</table>\n<input type=submit name=submit value=\"%s\">\n</form>\n\
 </body>\n</html>\n",
-	   MSG_DOIT);
+	   _(MSG_DOIT));
 }
 
 void
@@ -172,6 +183,8 @@
     Str qs = NULL;
     struct parsed_tagarg *cgiarg;
     char *mode;
+    char *charset;
+    char *locale;
     char *sent_cookie;
 
     p = getenv("REQUEST_METHOD");
@@ -203,6 +216,16 @@
     }
 
     mode = tag_get_value(cgiarg, "mode");
+    charset = tag_get_value(cgiarg, "charset");
+#if ENABLE_NLS
+    locale = tag_get_value(cgiarg, "locale");
+    if (locale == NULL)
+	locale = "";
+    setlocale(LC_ALL, locale);
+    bindtextdomain(PACKAGE, LOCALEDIR);
+    textdomain(PACKAGE);
+#endif
+
     mailcapfile = Strnew_charp(expandPath(USER_MAILCAP));
     if (mode && !strcmp(mode, "edit")) {
 	char *referer;
@@ -219,7 +242,7 @@
     }
     else {
 	/* initial panel */
-	printMailcapPanel(mailcapfile->ptr);
+	printMailcapPanel(mailcapfile->ptr, charset);
     }
     return 0;