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

jvprat at users.sourceforge.net jvprat at users.sourceforge.net
Wed Sep 8 19:01:21 CEST 2010


Revision: 52638
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52638&view=rev
Author:   jvprat
Date:     2010-09-08 17:01:21 +0000 (Wed, 08 Sep 2010)

Log Message:
-----------
I18N: Don't use fuzzy translations.

- Tweaked create_translations to ignore fuzzy translations.
- Fixed some formatting and removed extra whitespaces.

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

Modified: scummvm/trunk/tools/create_translations/create_translations.cpp
===================================================================
--- scummvm/trunk/tools/create_translations/create_translations.cpp	2010-09-08 16:15:42 UTC (rev 52637)
+++ scummvm/trunk/tools/create_translations/create_translations.cpp	2010-09-08 17:01:21 UTC (rev 52638)
@@ -52,7 +52,7 @@
 	writeByte(fp, (uint8)(value & 0xFF));
 }
 
-int stringSize(const char* string) {
+int stringSize(const char *string) {
 	// Each string is preceded by its size coded on 2 bytes
 	if (string == NULL)
 		return 2;
@@ -63,7 +63,7 @@
 	// return 2 + len + pad;
 }
 
-void writeString(FILE *fp, const char* string) {
+void writeString(FILE *fp, const char *string) {
 	// Each string is preceded by its size coded on 2 bytes
 	if (string == NULL) {
 		writeUint16BE(fp, 0);
@@ -86,12 +86,12 @@
 	PoMessageList messageIds;
 	PoMessageEntryList **translations = new PoMessageEntryList*[argc - 1];
 	int numLangs = 0;
-	for (int i = 1 ; i < argc ; ++i) {
+	for (int i = 1; i < argc; ++i) {
 		translations[numLangs] = parsePoFile(argv[i], messageIds);
 		if (translations[numLangs] != NULL)
 			++numLangs;
 	}
-	
+
 	FILE *outFile;
 	int i, lang;
 	int len;
@@ -110,7 +110,7 @@
 
 	// Write number of translations
 	writeUint16BE(outFile, numLangs);
-	
+
 	// Write the length of each data block here.
 	// We could write it at the start of each block but that would mean that
 	// to go to block 4 we would have to go at the start of each preceding block,
@@ -123,7 +123,7 @@
 	//   3. First translation
 	//   4. Second translation
 	//   ...
-	
+
 	// Write length for translation description
 	len = 0;
 	for (lang = 0; lang < numLangs; lang++) {
@@ -131,7 +131,7 @@
 		len += stringSize(translations[lang]->languageName());
 	}
 	writeUint16BE(outFile, len);
-	
+
 	// Write size for the original language (english) block
 	// It starts with the number of strings coded on 2 bytes followed by each
 	// string (two bytes for the number of chars and the string itself).
@@ -158,13 +158,13 @@
 		writeString(outFile, translations[lang]->language());
 		writeString(outFile, translations[lang]->languageName());
 	}
-	
+
 	// Write original messages
 	writeUint16BE(outFile, messageIds.size());
 	for (i = 0; i < messageIds.size(); ++i) {
 		writeString(outFile, messageIds[i]);
 	}
-	
+
 	// Write translations
 	for (lang = 0; lang < numLangs; lang++) {
 		writeUint16BE(outFile, translations[lang]->size());
@@ -177,11 +177,11 @@
 	}
 
 	fclose(outFile);
-	
+
 	// Clean the memory
 	for (i = 0; i < numLangs; ++i)
 		delete translations[i];
-	delete [] translations;
+	delete[] translations;
 
 	return 0;
 }

Modified: scummvm/trunk/tools/create_translations/po_parser.cpp
===================================================================
--- scummvm/trunk/tools/create_translations/po_parser.cpp	2010-09-08 16:15:42 UTC (rev 52637)
+++ scummvm/trunk/tools/create_translations/po_parser.cpp	2010-09-08 17:01:21 UTC (rev 52638)
@@ -34,14 +34,14 @@
 
 PoMessageList::~PoMessageList() {
 	for (int i = 0; i < _size; ++i)
-		delete [] _messages[i];
-	delete [] _messages;
+		delete[] _messages[i];
+	delete[] _messages;
 }
 
 void PoMessageList::insert(const char *msg) {
 	if (msg == NULL || *msg == '\0')
 		return;
-	
+
 	// binary-search for the insertion index
 	int leftIndex = 0;
 	int rightIndex = _size - 1;
@@ -64,7 +64,7 @@
 			newMessages[i] = _messages[i];
 		for (int i = leftIndex; i < _size; ++i)
 			newMessages[i + 1] = _messages[i];
-		delete [] _messages;
+		delete[] _messages;
 		_messages = newMessages;
 	} else {
 		for (int i = _size - 1; i >= leftIndex; --i)
@@ -78,11 +78,11 @@
 int PoMessageList::findIndex(const char *msg) {
 	if (msg == NULL || *msg == '\0')
 		return -1;
-	
+
 	// binary-search for the message
 	int leftIndex = 0;
 	int rightIndex = _size - 1;
-	
+
 	while (rightIndex >= leftIndex) {
 		const int midIndex = (leftIndex + rightIndex) / 2;
 		const int compareResult = strcmp(msg, _messages[midIndex]);
@@ -122,12 +122,12 @@
 }
 
 PoMessageEntryList::~PoMessageEntryList() {
-	delete [] _lang;
-	delete [] _charset;
-	delete [] _langName;
+	delete[] _lang;
+	delete[] _charset;
+	delete[] _langName;
 	for (int i = 0; i < _size; ++i)
 		delete _list[i];
-	delete [] _list;
+	delete[] _list;
 }
 
 void PoMessageEntryList::addMessageEntry(const char *translation, const char *message, const char *context) {
@@ -136,17 +136,17 @@
 		// We get the charset and the language name from the translation string
 		char *str = parseLine(translation, "Language:");
 		if (str != NULL) {
-			delete [] _langName;
+			delete[] _langName;
 			_langName = str;
 		}
 		str = parseLine(translation, "charset=");
 		if (str != NULL) {
-			delete [] _charset;
+			delete[] _charset;
 			_charset = str;
 		}
 		return;
-	}	
-	
+	}
+
 	// binary-search for the insertion index
 	int leftIndex = 0;
 	int rightIndex = _size - 1;
@@ -189,8 +189,8 @@
 		if (contextIndex < leftIndex && _list[contextIndex]->msgctxt == NULL && strcmp(translation, _list[contextIndex]->msgstr) == 0)
 			return;
 	}
-	
-	
+
+
 	if (_size + 1 > _allocated) {
 		_allocated += 100;
 		PoMessageEntry **newList = new PoMessageEntry*[_allocated];
@@ -198,7 +198,7 @@
 			newList[i] = _list[i];
 		for (int i = leftIndex; i < _size; ++i)
 			newList[i + 1] = _list[i];
-		delete [] _list;
+		delete[] _list;
 		_list = newList;
 	} else {
 		for (int i = _size - 1; i >= leftIndex; --i)
@@ -206,7 +206,7 @@
 	}
 	_list[leftIndex] = new PoMessageEntry(translation, message, context);
 	++_size;
-	
+
 	if (context == NULL || *context == '\0') {
 		// Remove identical translations for a specific context (see comment above)
 		int contextIndex = leftIndex + 1;
@@ -228,7 +228,7 @@
 		}
 		_size -= removed;
 	}
-	
+
 }
 
 const char *PoMessageEntryList::language() const {
@@ -258,10 +258,10 @@
 	FILE *inFile = fopen(file, "r");
 	if (!inFile)
 		return NULL;
-	
+
 	char msgidBuf[1024], msgctxtBuf[1024], msgstrBuf[1024];
-	char line[1024], *currentBuf = NULL;
-	
+	char line[1024], *currentBuf = msgstrBuf;
+
 	// Get language from file name and create PoMessageEntryList
 	int index = 0, start_index = strlen(file) - 1;
 	while (start_index > 0 && file[start_index - 1] != '/' && file[start_index - 1] != '\\') {
@@ -273,34 +273,53 @@
 	}
 	msgidBuf[index] = '\0';
 	PoMessageEntryList *list = new PoMessageEntryList(msgidBuf);
-	
+
+	// Initialize the message attributes.
+	bool fuzzy = false;
+	bool fuzzy_next = false;
+
 	// Parse the file line by line.
 	// The msgstr is always the last line of an entry (i.e. msgid and msgctxt always
 	// precede the corresponding msgstr).
 	msgidBuf[0] = msgstrBuf[0] = msgctxtBuf[0] = '\0';
 	while (!feof(inFile) && fgets(line, 1024, inFile)) {
+		if (line[0] == '#' && line[1] == ',') {
+			// Handle message attributes.
+			if (strstr(line, "fuzzy")) {
+				fuzzy_next = true;
+				continue;
+			}
+		}
 		// Skip empty and comment line
 		if (*line == '\n' || *line == '#')
 			continue;
 		if (strncmp(line, "msgid", 5) == 0) {
 			if (currentBuf == msgstrBuf) {
 				// add previous entry
-				if (*msgstrBuf != '\0') {
+				if (*msgstrBuf != '\0' && !fuzzy) {
 					messages.insert(msgidBuf);
 					list->addMessageEntry(msgstrBuf, msgidBuf, msgctxtBuf);
 				}
 				msgidBuf[0] = msgstrBuf[0] = msgctxtBuf[0] = '\0';
+
+				// Reset the attribute flags.
+				fuzzy = fuzzy_next;
+				fuzzy_next = false;
 			}
 			strcpy(msgidBuf, stripLine(line));
 			currentBuf = msgidBuf;
 		} else if (strncmp(line, "msgctxt", 7) == 0) {
 			if (currentBuf == msgstrBuf) {
 				// add previous entry
-				if (*msgstrBuf != '\0') {
+				if (*msgstrBuf != '\0' && !fuzzy) {
 					messages.insert(msgidBuf);
 					list->addMessageEntry(msgstrBuf, msgidBuf, msgctxtBuf);
 				}
 				msgidBuf[0] = msgstrBuf[0] = msgctxtBuf[0] = '\0';
+
+				// Reset the attribute flags
+				fuzzy = fuzzy_next;
+				fuzzy_next = false;
 			}
 			strcpy(msgctxtBuf, stripLine(line));
 			currentBuf = msgctxtBuf;
@@ -313,7 +332,7 @@
 				strcat(currentBuf, stripLine(line));
 		}
 	}
-	
+
 	fclose(inFile);
 	return list;
 }
@@ -327,8 +346,8 @@
 	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];
+	while (start + i < len && (line[start + i] != '"' || (i > 0 && line[start + i - 1] == '\\'))) {
+		line[i] = line[start + i];
 		++i;
 	}
 	line[i] = '\0';

Modified: scummvm/trunk/tools/create_translations/po_parser.h
===================================================================
--- scummvm/trunk/tools/create_translations/po_parser.h	2010-09-08 16:15:42 UTC (rev 52637)
+++ scummvm/trunk/tools/create_translations/po_parser.h	2010-09-08 17:01:21 UTC (rev 52638)
@@ -34,7 +34,7 @@
 
 	void insert(const char *msg);
 	int findIndex(const char *msg);
-	
+
 	int size() const;
 	const char *operator[](int) const;
 
@@ -69,9 +69,9 @@
 		}
 	}
 	~PoMessageEntry() {
-		delete [] msgstr;
-		delete [] msgid;
-		delete [] msgctxt;
+		delete[] msgstr;
+		delete[] msgid;
+		delete[] msgctxt;
 	}
 };
 
@@ -80,11 +80,11 @@
  */
 class PoMessageEntryList {
 public:
-	PoMessageEntryList(const char* language);
+	PoMessageEntryList(const char *language);
 	~PoMessageEntryList();
 
 	void addMessageEntry(const char *translation, const char *message, const char *context = NULL);
-	
+
 	const char *language() const;
 	const char *languageName() const;
 	const char *charset() const;


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