aboutsummaryrefslogtreecommitdiff
path: root/tools/create_translations
diff options
context:
space:
mode:
authorThierry Crozat2010-08-30 22:10:32 +0000
committerThierry Crozat2010-08-30 22:10:32 +0000
commitfc05e8a4ff8cc1f67d1ee1690bb6ef3ed8fd9a83 (patch)
tree873503172e2c34f93bf53ce57d0aec1f0ad35a5f /tools/create_translations
parent8ee7867831a1b9ed9dc27be4bf927d9be70ee2bf (diff)
downloadscummvm-rg350-fc05e8a4ff8cc1f67d1ee1690bb6ef3ed8fd9a83.tar.gz
scummvm-rg350-fc05e8a4ff8cc1f67d1ee1690bb6ef3ed8fd9a83.tar.bz2
scummvm-rg350-fc05e8a4ff8cc1f67d1ee1690bb6ef3ed8fd9a83.zip
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). svn-id: r52459
Diffstat (limited to 'tools/create_translations')
-rw-r--r--tools/create_translations/po_parser.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/create_translations/po_parser.cpp b/tools/create_translations/po_parser.cpp
index 84de73355f..3d8e2547a0 100644
--- a/tools/create_translations/po_parser.cpp
+++ b/tools/create_translations/po_parser.cpp
@@ -175,6 +175,22 @@ void PoMessageEntryList::addMessageEntry(const char *translation, const char *me
}
// 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 @@ void PoMessageEntryList::addMessageEntry(const char *translation, const char *me
}
_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 {