[Scummvm-cvs-logs] SF.net SVN: scummvm:[52739] scummvm/trunk/tools/create_translations/ po_parser.cpp

criezy at users.sourceforge.net criezy at users.sourceforge.net
Thu Sep 16 01:12:29 CEST 2010


Revision: 52739
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52739&view=rev
Author:   criezy
Date:     2010-09-15 23:12:29 +0000 (Wed, 15 Sep 2010)

Log Message:
-----------
I18N: Fix create_translation tool when string contain special characters

The english or translated strings in the PO file might have representations of special characters (e.g. '\n') or protected characters (e.g. '\"') visible as
in the source code. However at run time ScummVM expects them to be
the special characters and not their visible representations. Now the
create_translations tool does the substitution if it finds such characters.

Modified Paths:
--------------
    scummvm/trunk/tools/create_translations/po_parser.cpp

Modified: scummvm/trunk/tools/create_translations/po_parser.cpp
===================================================================
--- scummvm/trunk/tools/create_translations/po_parser.cpp	2010-09-15 22:30:00 UTC (rev 52738)
+++ scummvm/trunk/tools/create_translations/po_parser.cpp	2010-09-15 23:12:29 UTC (rev 52739)
@@ -340,15 +340,42 @@
 char *stripLine(char *line) {
 	// This function modifies line in place and return it.
 	// Keep only the text between the first two unprotected quotes.
+	// It also look for literal special characters (e.g. preceded by '\n', '\\', '\"', '\'', '\t')
+	// and replace them by the special character so that strcmp() can match them at run time.
 	// Look for the first quote
 	int start = 0;
 	int len = strlen(line);
 	while (start < len && line[start++] != '"') {}
 	// shift characters until we reach the end of the string or an unprotected quote
-	int i = 0;
-	while (start + i < len && (line[start + i] != '"' || (i > 0 && line[start + i - 1] == '\\'))) {
-		line[i] = line[start + i];
-		++i;
+	int i = 0, j = 0;
+	while (start + i + j < len && line[start + i + j] != '"') {
+		if (line[start + i + j] == '\\') {
+			switch (line[start + i + j + 1]) {
+			case 'n':
+				line[i++] = '\n';
+				break;
+			case 't':
+				line[i++] = '\t';
+				break;				
+			case '\"':
+				line[i++] = '\"';
+				break;
+			case '\'':
+				line[i++] = '\'';
+				break;				
+			case '\\':
+				line[i++] = '\\';
+				break;
+			default:
+				// Just skip
+				fprintf(stdout, "Unsupported special character \"%c%c\" in string. Please contact ScummVM developers.\n", line[start + i + j], line[start + i + j + 1]);
+				++j;
+			}
+			++j;
+		} else {
+			line[i] = line[start + i + j];
+			++i;
+		}
 	}
 	line[i] = '\0';
 	return line;
@@ -367,10 +394,9 @@
 	while (*str != '\0' && isspace(*str)) {
 		++str;
 	}
-	// Find string length (top at the first '\\'
-	// (since the string we want is followed by a '\\n')
+	// Find string length (stop at the first '\n')
 	int len = 0;
-	while (str[len] != '\0' && str[len] != '\\') {
+	while (str[len] != '\0' && str[len] != '\n') {
 		++len;
 	}
 	if (len == 0)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list