[Scummvm-cvs-logs] SF.net SVN: scummvm:[52459] scummvm/trunk/tools/create_translations/ po_parser.cpp
criezy at users.sourceforge.net
criezy at users.sourceforge.net
Tue Aug 31 00:10:32 CEST 2010
Revision: 52459
http://scummvm.svn.sourceforge.net/scummvm/?rev=52459&view=rev
Author: criezy
Date: 2010-08-30 22:10:32 +0000 (Mon, 30 Aug 2010)
Log Message:
-----------
I18N: Modify create-translations tool to remove duplicate translations
The TranslationManager in ScummVM will pick up the translation associated
to no context if present and if a translation could not be found for a specific
context. Based on this, the create_translations tool will now remove the
translation associated to a specific context if the same message has the
same translation associated to no context. This generate a smaller
translation.dat file, and this should also slightly improve performances (less
strings to load from the file and smaller list in which to look for a translated
message).
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-08-30 17:12:41 UTC (rev 52458)
+++ scummvm/trunk/tools/create_translations/po_parser.cpp 2010-08-30 22:10:32 UTC (rev 52459)
@@ -175,6 +175,22 @@
}
// We now have rightIndex = leftIndex - 1 and we need to insert the new message
// between the two (i.a. at leftIndex).
+ // However since the TranslationManager will pick the translation associated to no
+ // context if it is not present for a specific context, we can optimize the file
+ // size, memory used at run-time and performances (less strings to read from the file
+ // and less strings to look for) by avoiding duplicate.
+ if (context != NULL && *context != '\0') {
+ // Check if we have the same translation for no context
+ int contextIndex = leftIndex - 1;
+ while (contextIndex >= 0 && strcmp (message, _list[contextIndex]->msgid) == 0) {
+ --contextIndex;
+ }
+ ++contextIndex;
+ 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];
@@ -190,6 +206,29 @@
}
_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;
+ int removed = 0;
+ while (contextIndex < _size && strcmp(message, _list[contextIndex]->msgid) == 0) {
+ if (strcmp(translation, _list[contextIndex]->msgstr) == 0) {
+ delete _list[contextIndex];
+ ++removed;
+ } else {
+ _list[contextIndex - removed] = _list[contextIndex];
+ }
+ ++contextIndex;
+ }
+ if (removed > 0) {
+ while (contextIndex < _size) {
+ _list[contextIndex - removed] = _list[contextIndex];
+ ++contextIndex;
+ }
+ }
+ _size -= removed;
+ }
+
}
const char *PoMessageEntryList::language() 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