[Scummvm-cvs-logs] SF.net SVN: scummvm:[54206] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Nov 11 19:22:35 CET 2010


Revision: 54206
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54206&view=rev
Author:   fingolfin
Date:     2010-11-11 18:22:35 +0000 (Thu, 11 Nov 2010)

Log Message:
-----------
COMMON: Cleanup translation manager code; add FIXME

Modified Paths:
--------------
    scummvm/trunk/common/translation.cpp
    scummvm/trunk/common/translation.h

Modified: scummvm/trunk/common/translation.cpp
===================================================================
--- scummvm/trunk/common/translation.cpp	2010-11-11 17:05:33 UTC (rev 54205)
+++ scummvm/trunk/common/translation.cpp	2010-11-11 18:22:35 UTC (rev 54206)
@@ -31,7 +31,7 @@
 
 #define TRANSLATIONS_DAT_VER 2
 
-#include "translation.h"
+#include "common/translation.h"
 #include "common/archive.h"
 #include "common/config-manager.h"
 
@@ -57,6 +57,7 @@
 	loadTranslationsInfoDat();
 
 #ifdef USE_DETECTLANG
+// FIXME: language detection should be done via an OSystem API.
 #ifdef WIN32
 	// We can not use "setlocale" (at least not for MSVC builds), since it
 	// will return locales like: "English_USA.1252", thus we need a special
@@ -124,7 +125,7 @@
 TranslationManager::~TranslationManager() {
 }
 
-void TranslationManager::setLanguage(const char *lang) {
+void TranslationManager::setLanguage(const String &lang) {
 	// Get lang index
 	int langIndex = -1;
 	String langStr(lang);
@@ -151,11 +152,11 @@
 	}
 }
 
-const char *TranslationManager::getTranslation(const char *message) {
+const char *TranslationManager::getTranslation(const char *message) const {
 	return getTranslation(message, NULL);
 }
 
-const char *TranslationManager::getTranslation(const char *message, const char *context) {
+const char *TranslationManager::getTranslation(const char *message, const char *context) const {
 	// if no language is set or message is empty, return msgid as is
 	if (_currentTranslationMessages.empty() || *message == '\0')
 		return message;
@@ -207,23 +208,23 @@
 	return message;
 }
 
-const char *TranslationManager::getCurrentCharset() {
+String TranslationManager::getCurrentCharset() const {
 	if (_currentCharset.empty())
 		return "ASCII";
-	return _currentCharset.c_str();
+	return _currentCharset;
 }
 
-const char *TranslationManager::getCurrentLanguage() {
+String TranslationManager::getCurrentLanguage() const {
 	if (_currentLang == -1)
 		return "C";
-	return _langs[_currentLang].c_str();
+	return _langs[_currentLang];
 }
 
-String TranslationManager::getTranslation(const String &message) {
+String TranslationManager::getTranslation(const String &message) const {
 	return getTranslation(message.c_str());
 }
 
-String TranslationManager::getTranslation(const String &message, const String &context) {
+String TranslationManager::getTranslation(const String &message, const String &context) const {
 	return getTranslation(message.c_str(), context.c_str());
 }
 
@@ -240,7 +241,7 @@
 	return languages;
 }
 
-int TranslationManager::parseLanguage(const String lang) {
+int TranslationManager::parseLanguage(const String &lang) const {
 	for (unsigned int i = 0; i < _langs.size(); i++) {
 		if (lang == _langs[i])
 			return i + 1;
@@ -249,7 +250,7 @@
 	return kTranslationBuiltinId;
 }
 
-const char *TranslationManager::getLangById(int id) {
+String TranslationManager::getLangById(int id) const {
 	switch (id) {
 	case kTranslationAutodetectId:
 		return "";
@@ -444,29 +445,29 @@
 
 TranslationManager::~TranslationManager() {}
 
-void TranslationManager::setLanguage(const char *lang) {}
+void TranslationManager::setLanguage(const String &lang) {}
 
-const char *TranslationManager::getLangById(int id) {
-	return "";
+String TranslationManager::getLangById(int id) const {
+	return String();
 }
 
-int TranslationManager::parseLanguage(const String lang) {
+int TranslationManager::parseLanguage(const String lang) const {
 	return kTranslationBuiltinId;
 }
 
-const char *TranslationManager::getTranslation(const char *message) {
+const char *TranslationManager::getTranslation(const char *message) const {
 	return message;
 }
 
-String TranslationManager::getTranslation(const String &message) {
+String TranslationManager::getTranslation(const String &message) const {
 	return message;
 }
 
-const char *TranslationManager::getTranslation(const char *message, const char *) {
+const char *TranslationManager::getTranslation(const char *message, const char *) const {
 	return message;
 }
 
-String TranslationManager::getTranslation(const String &message, const String &) {
+String TranslationManager::getTranslation(const String &message, const String &) const {
 	return message;
 }
 
@@ -474,11 +475,11 @@
 	return TLangArray();
 }
 
-const char *TranslationManager::getCurrentCharset() {
+String TranslationManager::getCurrentCharset() const {
 	return "ASCII";
 }
 
-const char *TranslationManager::getCurrentLanguage() {
+String *TranslationManager::getCurrentLanguage() const {
 	return "C";
 }
 

Modified: scummvm/trunk/common/translation.h
===================================================================
--- scummvm/trunk/common/translation.h	2010-11-11 17:05:33 UTC (rev 54205)
+++ scummvm/trunk/common/translation.h	2010-11-11 18:22:35 UTC (rev 54206)
@@ -73,7 +73,7 @@
 	 * @param id Id of the language
 	 * @return the matching string description of the language
 	 */
-	const char *getLangById(int id);
+	String getLangById(int id) const;
 
 	/**
 	 * Sets the current translation language to the one specified in the
@@ -82,7 +82,7 @@
 	 *
 	 * @param lang Language to setup.
 	 */
-	void setLanguage(const char *lang);
+	void setLanguage(const String &lang);
 
 	/**
 	 * Sets the current translation language to the one specified by the
@@ -101,21 +101,21 @@
 	 * @return id of the language or kTranslationBuiltinId in case the
 	 *         language could not be found.
 	 */
-	int parseLanguage(const String lang);
+	int parseLanguage(const String &lang) const;
 
 	/**
 	 * Returns the translation into the current language of the parameter
 	 * message. In case the message isn't found in the translation catalog,
 	 * it returns the original untranslated message.
 	 */
-	const char *getTranslation(const char *message);
+	const char *getTranslation(const char *message) const;
 
 	/**
 	 * Returns the translation into the current language of the parameter
 	 * message. In case the message isn't found in the translation catalog,
 	 * it returns the original untranslated message.
 	 */
-	String getTranslation(const String &message);
+	String getTranslation(const String &message) const;
 
 	/**
 	 * Returns the translation into the current language of the parameter
@@ -126,7 +126,7 @@
 	 * translation, otherwise it will look for a translation for the same
 	 * massage without a context or with a different context.
 	 */
-	const char *getTranslation(const char *message, const char *context);
+	const char *getTranslation(const char *message, const char *context) const;
 
 	/**
 	 * Returns the translation into the current language of the parameter
@@ -137,7 +137,7 @@
 	 * translation, otherwise it will look for a translation for the same
 	 * massage without a context or with a different context.
 	 */
-	String getTranslation(const String &message, const String &context);
+	String getTranslation(const String &message, const String &context) const;
 
 	/**
 	 * Returns a list of supported languages.
@@ -149,12 +149,12 @@
 	/**
 	 * Returns charset specified by selected translation language
 	 */
-	const char *getCurrentCharset();
+	String getCurrentCharset() const;
 
 	/**
 	 * Returns currently selected translation language
 	 */
-	const char *getCurrentLanguage();
+	String getCurrentLanguage() const;
 
 private:
 #ifdef USE_TRANSLATION


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