aboutsummaryrefslogtreecommitdiff
path: root/tools/create_translations
diff options
context:
space:
mode:
authorThierry Crozat2010-09-15 23:12:29 +0000
committerThierry Crozat2010-09-15 23:12:29 +0000
commitb77434c415f22aad57251b61014a1d66971c950c (patch)
tree965cc6feec562d665a55a52eb113c7dcfb038cfb /tools/create_translations
parentb2c57117fd0749f0c39dbe6b9de65d2c0566ea1d (diff)
downloadscummvm-rg350-b77434c415f22aad57251b61014a1d66971c950c.tar.gz
scummvm-rg350-b77434c415f22aad57251b61014a1d66971c950c.tar.bz2
scummvm-rg350-b77434c415f22aad57251b61014a1d66971c950c.zip
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. svn-id: r52739
Diffstat (limited to 'tools/create_translations')
-rw-r--r--tools/create_translations/po_parser.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/tools/create_translations/po_parser.cpp b/tools/create_translations/po_parser.cpp
index a6a773bece..e730ea074f 100644
--- a/tools/create_translations/po_parser.cpp
+++ b/tools/create_translations/po_parser.cpp
@@ -340,15 +340,42 @@ PoMessageEntryList *parsePoFile(const char *file, PoMessageList& messages) {
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 @@ char *parseLine(const char *line, const char *field) {
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)