All pastes #196716 Raw Edit

Nagappan

public text v1 · immutable
·published 2006-10-10 20:43 UTC
rendered paste body
Index: python/ldtp.py
===================================================================
RCS file: /cvs/ldtp/ldtp/python/ldtp.py,v
retrieving revision 1.40
diff -u -p -r1.40 ldtp.py
--- python/ldtp.py	28 Sep 2006 11:26:45 -0000	1.40
+++ python/ldtp.py	10 Oct 2006 20:43:23 -0000
@@ -2954,6 +2954,12 @@ def bindtext (packageName, localeDir, mo
 	OUTPUT: TODO"""
 	try:
 		_requestId  = str (random.randint (0, sys.maxint))
+		_message = generatexml ('setlocale', _requestId, os.getenv ('LANG'))
+		sendpacket (_message)
+		_responseStatus, _responseData = getresponse (_requestId)
+		if _responseStatus[0] != 0:
+			raise LdtpExecutionError ('bindtext:setlocale failed: ' + _responseStatus[1])
+		_requestId  = str (random.randint (0, sys.maxint))
 		_message = generatexml ('bindtext', _requestId, packageName, localeDir, mode)
 		sendpacket (_message)
 		_responseStatus, _responseData = getresponse (_requestId)
Index: src/client-handler.c
===================================================================
RCS file: /cvs/ldtp/ldtp/src/client-handler.c,v
retrieving revision 1.31
diff -u -p -r1.31 client-handler.c
--- src/client-handler.c	27 Sep 2006 18:02:36 -0000	1.31
+++ src/client-handler.c	10 Oct 2006 20:43:24 -0000
@@ -589,9 +589,7 @@ createpo (gchar *package_name, gchar *lo
 		g_free (mopathfilename);
 	}
 }
-#endif
 
-#ifdef ENABLE_LOCALIZATION
 static void
 deletepo (char *filename, FILE *log_fp, LDTPError **err)
 {
@@ -624,18 +622,24 @@ bind_text (LDTPClientContext *cctxt, gch
 	 * FIXME
 	 * Currently only mo files are handled
 	 */
-	filename = g_strdup_printf ("%s/%s-%d.po", g_get_tmp_dir (),
-				    package_name, g_random_int_range (G_MININT, G_MAXINT));
-	createpo (package_name, locale_dir, filename, mode, cctxt->log_fp, err);
-	if (*err && (*err)->err_code != LDTP_ERROR_SUCCESS) {
-		*err = ldtp_error_get_error (LDTP_ERROR_UNABLE_TO_CREATE_PO);
-		log_msg (LDTP_LOG_CAUSE, (*err)->message, cctxt->log_fp);
-		return;
+	if (g_ascii_strcasecmp (mode, "mo") == 0) {
+		filename = g_strdup_printf ("%s/%s-%d.po", g_get_tmp_dir (),
+					    package_name, g_random_int_range (G_MININT, G_MAXINT));
+		createpo (package_name, locale_dir, filename, mode, cctxt->log_fp, err);
+		if (*err && (*err)->err_code != LDTP_ERROR_SUCCESS) {
+			*err = ldtp_error_get_error (LDTP_ERROR_UNABLE_TO_CREATE_PO);
+			log_msg (LDTP_LOG_CAUSE, (*err)->message, cctxt->log_fp);
+			return;
+		}
+	}
+	else {
+		filename = g_strdup_printf ("%s/%s", locale_dir, package_name);
 	}
 	temp_flag = init_catalog (filename, cctxt->log_fp);
 	if (!cctxt->locale_set && temp_flag)
 		cctxt->locale_set = temp_flag;
-	deletepo (filename, cctxt->log_fp, err);
+	if (g_ascii_strcasecmp (mode, "mo") == 0)
+		deletepo (filename, cctxt->log_fp, err);
 	g_free (filename);
 #else
 	g_print ("Localization option not enabled in LDTP\n");
@@ -712,6 +716,13 @@ handle_request (LDTPClientContext* cctxt
 		return;
 	}
 	switch (command) {
+	case LDTP_CMD_SETLOCALE:
+		if (cctxt->locale_lang)
+			g_free (cctxt->locale_lang);
+		cctxt->locale_lang = g_strdup (cctxt->req->context);
+		cctxt->locale_set = TRUE;
+		setlocale (LC_ALL, "");
+		return;
 	case LDTP_CMD_LAUNCHAPP: {
 		GError *error = NULL;
 		if (cctxt->req->component && g_ascii_strcasecmp(cctxt->req->component, "1") == 0) {
@@ -1430,7 +1441,6 @@ handle_client (void *ptr)
 	char *resp_pckt = NULL;
 
 	LDTPError* err = NULL;
-	gchar *locale_lang = NULL;
 
 	LDTPClientContext *cctxt = NULL;
 	Packet *pckt = NULL;
@@ -1443,18 +1453,7 @@ handle_client (void *ptr)
 	cctxt->resp = calloc (1, sizeof (LDTPResponse));
 	cctxt->sock_fd = *sock_fd;
 	cctxt->log_fp = NULL;
-
-	/*
-	  Check whether locale lang set or not
-	*/
-	locale_lang = getenv ("LANG");
-	if (locale_lang && 
-	    g_utf8_collate (locale_lang, "en_US.UTF-8") != 0) {
-		g_print ("Locale languages: %s\n", locale_lang);
-		cctxt->locale_set = TRUE;
-		setlocale (LC_ALL, "");
-	} else
-		cctxt->locale_set = FALSE;
+	cctxt->locale_set = FALSE;
 
 	while (1) {
 		packet_len = 0;
Index: src/ldtp-command.c
===================================================================
RCS file: /cvs/ldtp/ldtp/src/ldtp-command.c,v
retrieving revision 1.16
diff -u -p -r1.16 ldtp-command.c
--- src/ldtp-command.c	28 Sep 2006 11:26:03 -0000	1.16
+++ src/ldtp-command.c	10 Oct 2006 20:43:24 -0000
@@ -200,6 +200,7 @@ ldtp_command_init_command_table ()
 			ldtp_command_new ( LDTP_CMD_HASSTATE, "hasstate"),
 			ldtp_command_new ( LDTP_CMD_LAUNCHAPP, "launchapp"),
 			ldtp_command_new ( LDTP_CMD_SINGLECLICKROW, "singleclickrow"),
+			ldtp_command_new ( LDTP_CMD_SETLOCALE, "setlocale"),
 			NULL
 		};
 
Index: src/ldtp-command.h
===================================================================
RCS file: /cvs/ldtp/ldtp/src/ldtp-command.h,v
retrieving revision 1.16
diff -u -p -r1.16 ldtp-command.h
--- src/ldtp-command.h	28 Sep 2006 11:26:03 -0000	1.16
+++ src/ldtp-command.h	10 Oct 2006 20:43:24 -0000
@@ -174,7 +174,8 @@ enum _LDTPCommandId {
 	LDTP_CMD_STOPRECORD,
 	LDTP_CMD_HASSTATE,
 	LDTP_CMD_LAUNCHAPP,
-	LDTP_CMD_SINGLECLICKROW
+	LDTP_CMD_SINGLECLICKROW,
+	LDTP_CMD_SETLOCALE
 };
 
 struct _LDTPCommand {