[Scummvm-cvs-logs] SF.net SVN: scummvm:[52257] scummvm/trunk/common
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Sat Aug 21 15:21:10 CEST 2010
Revision: 52257
http://scummvm.svn.sourceforge.net/scummvm/?rev=52257&view=rev
Author: lordhoto
Date: 2010-08-21 13:21:09 +0000 (Sat, 21 Aug 2010)
Log Message:
-----------
i18n: Style fixes.
Modified Paths:
--------------
scummvm/trunk/common/translation.cpp
scummvm/trunk/common/translation.h
Modified: scummvm/trunk/common/translation.cpp
===================================================================
--- scummvm/trunk/common/translation.cpp 2010-08-21 13:03:35 UTC (rev 52256)
+++ scummvm/trunk/common/translation.cpp 2010-08-21 13:21:09 UTC (rev 52257)
@@ -43,14 +43,14 @@
namespace Common {
-bool operator<(const TLanguage& l1, const TLanguage& l2) {
- return strcmp(l1.name, l2.name) < 0;
+bool operator<(const TLanguage &l, const TLanguage &r) {
+ return strcmp(l.name, r.name) < 0;
}
#ifdef USE_TRANSLATION
// Translation enabled
-
+
TranslationManager::TranslationManager() : _currentLang(-1) {
loadTranslationsInfoDat();
@@ -128,19 +128,19 @@
String langStr(lang);
if (langStr.empty())
langStr = _syslang;
-
+
// Searching for a valid language
for (unsigned int i = 0; i < _langs.size() && langIndex == -1; ++i) {
if (langStr == _langs[i])
langIndex = i;
}
-
+
// Try partial match
for (unsigned int i = 0; i < _langs.size() && langIndex == -1; ++i) {
if (strncmp(langStr.c_str(), _langs[i].c_str(), 2) == 0)
langIndex = i;
}
-
+
// Load messages for that lang
// Call it even if the index is -1 to unload previously loaded translations
if (langIndex != _currentLang) {
@@ -153,11 +153,11 @@
// if no language is set or message is empty, return msgid as is
if (_currentTranslationMessages.empty() || *message == '\0')
return message;
-
+
// binary-search for the msgid
int leftIndex = 0;
int rightIndex = _currentTranslationMessages.size() - 1;
-
+
while (rightIndex >= leftIndex) {
const int midIndex = (leftIndex + rightIndex) / 2;
const PoMessageEntry * const m = &_currentTranslationMessages[midIndex];
@@ -171,7 +171,7 @@
else
leftIndex = midIndex + 1;
}
-
+
return message;
}
@@ -225,22 +225,22 @@
}
void TranslationManager::loadTranslationsInfoDat() {
- File in;
+ File in;
in.open("translations.dat");
-
+
if (!checkHeader(in))
return;
-
+
char buf[256];
int len;
-
+
// Get number of translations
int nbTranslations = in.readUint16BE();
// Skip all the block sizes
for (int i = 0 ; i < nbTranslations + 2 ; ++i)
in.readUint16BE();
-
+
// Read list of languages
_langs.resize(nbTranslations);
_langNames.resize(nbTranslations);
@@ -252,7 +252,7 @@
in.read(buf, len);
_langNames[i] = String(buf, len);
}
-
+
// Read messages
int numMessages = in.readUint16BE();
_messageIds.resize(numMessages);
@@ -272,42 +272,42 @@
warning("Invalid language index %d passed to TranslationManager::loadLanguageDat", index);
return;
}
-
- File in;
+
+ File in;
in.open("translations.dat");
if (!checkHeader(in))
return;
-
+
char buf[1024];
int len;
-
+
// Get number of translations
int nbTranslations = in.readUint16BE();
if (nbTranslations != (int)_langs.size()) {
warning("The 'translations.dat' file has changed since starting ScummVM. GUI translation will not be available");
return;
}
-
+
// Get size of blocks to skip.
int skipSize = 0;
for (int i = 0 ; i < index + 2 ; ++i)
skipSize += in.readUint16BE();
// We also need to skip the remaining block sizes
skipSize += 2 * (nbTranslations - index);
-
+
// Seek to start of block we want to read
in.seek(skipSize, SEEK_CUR);
-
+
// Read number of translated messages
int nbMessages = in.readUint16BE();
_currentTranslationMessages.resize(nbMessages);
-
+
// Read charset
len = in.readUint16BE();
in.read(buf, len);
_currentCharset = String(buf, len);
-
+
// Read messages
for (int i = 0; i < nbMessages; ++i) {
_currentTranslationMessages[i].msgid = in.readUint16BE();
@@ -320,29 +320,29 @@
bool TranslationManager::checkHeader(File& in) {
char buf[13];
int ver;
-
+
if (!in.isOpen()) {
warning("You're missing the 'translations.dat' file. GUI translation will not be available");
return false;
}
-
+
in.read(buf, 12);
buf[12] = '\0';
-
+
// Check header
if (strcmp(buf, "TRANSLATIONS")) {
warning("File 'translations.dat' is corrupt. GUI translation will not be available");
return false;
}
-
+
// Check version
ver = in.readByte();
-
+
if (ver != TRANSLATIONS_DAT_VER) {
warning("File 'translations.dat' is wrong version. Expected %d but got %d. GUI translation will not be available", TRANSLATIONS_DAT_VER, ver);
return false;
}
-
+
return true;
}
@@ -383,4 +383,5 @@
#endif // USE_TRANSLATION
-} // End of namespace Common
+} // End of namespace Common
+
Modified: scummvm/trunk/common/translation.h
===================================================================
--- scummvm/trunk/common/translation.h 2010-08-21 13:03:35 UTC (rev 52256)
+++ scummvm/trunk/common/translation.h 2010-08-21 13:21:09 UTC (rev 52257)
@@ -40,26 +40,19 @@
const char *name;
int id;
- TLanguage() {
- name = 0;
- id = 0;
- }
-
- TLanguage(const char *n, int i) {
- name = n;
- id = i;
- }
+ TLanguage() : name(0), id(0) {}
+ TLanguage(const char *n, int i) : name(n), id(i) {}
};
-
-bool operator<(const TLanguage&, const TLanguage&);
-
+
+bool operator<(const TLanguage &l, const TLanguage &r);
+
typedef Array<TLanguage> TLangArray;
struct PoMessageEntry {
int msgid;
String msgstr;
};
-
+
/**
* Message translation manager.
*/
@@ -140,21 +133,23 @@
* Load the list of languages from the translations.dat file
*/
void loadTranslationsInfoDat();
+
/**
* Load the translation for the given language from the translations.dat file
*
* @param index of the language in the list of languages
*/
void loadLanguageDat(int);
+
/**
* Check the header of the given file to make sure it is a valid translations data file.
*/
bool checkHeader(File&);
-
+
String _syslang;
StringArray _langs;
StringArray _langNames;
-
+
StringArray _messageIds;
Array<PoMessageEntry> _currentTranslationMessages;
String _currentCharset;
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