Prechádzať zdrojové kódy

vcc: prepare to use gettext, but something is ugly

intirain 4 rokov pred
rodič
commit
f47dc63745
5 zmenil súbory, kde vykonal 49 pridanie a 7 odobranie
  1. 14 2
      Makefile
  2. 1 0
      include/vcc/config.h
  3. 1 1
      include/vcc/version.h
  4. 11 4
      main.c
  5. 22 0
      po/zh_CN.po

+ 14 - 2
Makefile

@@ -1,8 +1,12 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 17
-VCC_PATCH 		= 1
+VCC_MINOR 		= 18
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
+# change this to '/usr/share/' or '/opt/vcc/' etc
+INSTALL 		= $(shell pwd)
+MO_DIR 			= $(INSTALL)/lang/zh_CN/LC_MESSAGES
+
 VCC_COMPILE_TIME 	= $(shell date)
 VCC_COMPILE_BY 		= $(shell whoami)
 VCC_SEMVER 		= vcc $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH)$(VCC_STR)
@@ -23,8 +27,15 @@ all :
 	@echo "#define VCC_VERSION \"$(VCC_VERSION)\"" > include/vcc/version.h 
 	@echo "#define VCC_SEMVER \"$(VCC_SEMVER)\"" >> include/vcc/version.h 
 	@echo "#define VCC_DEFSERV \"$(VCC_DEFSERV)\"" > include/vcc/defserv.h 
+	@echo "#define INSTALL_PATH \"$(INSTALL)\"" > include/vcc/config.h 
 	@$(MAKE) -C plugins/ 
 	@$(MAKE) $(target) $(MAKEFLAGS)
+	@$(MAKE) mo
+
+mo : 
+	@mkdir -p $(MO_DIR)
+	@msgfmt --check --verbose --output-file $(MO_DIR)/vcc.mo po/zh_CN.po 
+
 
 $(target) : 	$(objs) $(srcs)
 	@$(CC) $(objs) $(CFLAGS) -o $(target)
@@ -36,6 +47,7 @@ $(target) : 	$(objs) $(srcs)
 
 .PHONY clean : 
 	$(RM) $(objs) $(target) -f  
+	$(RM) -rf lang 
 	@$(MAKE) -C plugins/ clean
 
 w :

+ 1 - 0
include/vcc/config.h

@@ -0,0 +1 @@
+#define INSTALL_PATH "/root/vcc"

+ 1 - 1
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.17.1 Sat May  7 21:30:07 CST 2022 root"
+#define VCC_VERSION "VCC 1.17.1 Sat May  7 22:17:53 CST 2022 root"
 #define VCC_SEMVER "vcc 1.17.1-rc "

+ 11 - 4
main.c

@@ -35,6 +35,7 @@
 #include <poll.h>
 #include <signal.h>
 #include <getopt.h>
+#include <libintl.h>
 
 #include <klist.h>
 #include <vcc/vcc.h>
@@ -42,7 +43,8 @@
 #include <vcc/robot.h>
 #include <vcc/plugin.h>
 #include <vcc/pretty.h>
-#include <vcc/defserv.h> 
+#include <vcc/defserv.h>
+#include <vcc/config.h>
 
 
 /* we tried to use libreadline, but after using that, we feel strange 
@@ -67,6 +69,8 @@ int init_socket(const char *server_addr, int server_port);
 
 int 		fd;
 
+#define _(s) gettext(s)
+
 /* normally. it belongs to the foreground pgroup, all messages write to terminal. */
 #define MODE_NORMAL 	1
 /* robot mode. we run in the background pgroup, and give all the messages to the plugin specified. */
@@ -145,7 +149,7 @@ static int login(int got_usrname) {
 	char *passwd;
 
 	if (!got_usrname) {
-		fprintf(stderr, "login as: ");
+		fprintf(stderr, _("login as: "));
 		scanf("%s", usrname);
 	}
 
@@ -295,11 +299,14 @@ int main(int argc, char **argv) {
 	(void) argc;
 
 #ifdef _WIN32
-	setlocale(LC_ALL, ".UTF-8");
+	setlocale(LC_ALL, "");
 #else
-	setlocale(LC_ALL, "C.UTF-8");
+	setlocale(LC_ALL, "");
 #endif
 
+	bindtextdomain("vcc", "lang");
+	textdomain("vcc");
+
 	printf(VCC_VERSION "\n");
 
 	got_usrname = parse_args(argc, argv, &port, &ip);

+ 22 - 0
po/zh_CN.po

@@ -0,0 +1,22 @@
+# Simplified Chinese translation for vcc. 
+# This file is distributed under the same license as the vcc package. 
+# Ruiyang Peng (aka intirain) <intirain@163.com>, 2022
+# 
+
+msgid ""
+msgstr ""
+"Project-Id-Version: vcc 1.17.1\n"
+"Report-Msgid-Bugs-To: intirain@163.com\n"
+"POT-Creation-Date: 2022-05-07 22:05\n"
+"PO-Revision-Date: 2022-05-07 22:05\n"
+"Last-Translator: Ruiyang Peng (intirain) <intirain@163.com>\n"
+"Language-Team: Chinese (simplified) <intirain@163.com>\n"
+"Language: zh_CN\n"
+"X-Bugs: Report translation errors to the Language-Team address. \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "login as: "
+msgstr "登录为:"
+