Changeset 1052 for code/trunk/src/orxonox/core/Language.cc
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/Language.cc
r871 r1052 28 28 /** 29 29 @file Language.cc 30 @brief Implementation of the Language and the LanguageEntry class .30 @brief Implementation of the Language and the LanguageEntry classes. 31 31 */ 32 32 33 33 #include <fstream> 34 34 35 #include "CoreIncludes.h"36 35 #include "Language.h" 36 #include "CoreSettings.h" 37 37 38 38 namespace orxonox … … 47 47 LanguageEntry::LanguageEntry(const std::string& fallbackEntry) 48 48 { 49 RegisterRootObject(LanguageEntry);50 51 49 this->fallbackEntry_ = fallbackEntry; 52 50 this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned … … 61 59 { 62 60 // Check if the translation is more than just an empty string 63 if ( localisation.compare("") != 0)61 if ((localisation != "") && (localisation.size() > 0)) 64 62 { 65 63 this->localisedEntry_ = localisation; … … 91 89 Language::Language() 92 90 { 93 RegisterRootObject(Language);94 95 91 this->defaultLanguage_ = "default"; 96 92 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 101 97 102 98 /** 103 @brief Function to collect the SetConfigValue-macro calls.104 */105 void Language::setConfigValues()106 {107 SetConfigValue(language_, this->defaultLanguage_).description("The language of the ingame text");108 109 // Read the translation file after the language was configured110 this->readTranslatedLanguageFile();111 }112 113 /**114 99 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 115 100 @return The reference to the only existing instance … … 117 102 Language& Language::getLanguage() 118 103 { 119 // Use static variables to avoid conflicts while executing this code before main() 120 static Language theOnlyLanguageObject = Language(); 121 static bool bCreatingTheOnlyLanguageObject = true; 122 123 // This workaround is used to set a description of the own config value without creating an infinite recursion 124 if (bCreatingTheOnlyLanguageObject) 125 { 126 bCreatingTheOnlyLanguageObject = false; 127 theOnlyLanguageObject.setConfigValues(); 128 } 129 130 return theOnlyLanguageObject; 104 static Language instance = Language(); 105 return instance; 131 106 } 132 107 … … 244 219 245 220 // Check if the line is empty 246 if ( lineString.compare("") != 0)221 if ((lineString != "") && (lineString.size() > 0)) 247 222 { 248 223 unsigned int pos = lineString.find('='); … … 252 227 this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1)); 253 228 else 229 { 254 230 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->defaultLanguage_) << std::endl; 231 } 255 232 } 256 233 } … … 264 241 void Language::readTranslatedLanguageFile() 265 242 { 266 COUT(4) << "Read translated language file (" << this->language_<< ")." << std::endl;243 COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl; 267 244 268 245 // Open the file 269 246 std::ifstream file; 270 file.open(getFileName( this->language_).c_str(), std::fstream::in);247 file.open(getFileName(CoreSettings::getLanguage()).c_str(), std::fstream::in); 271 248 272 249 if (!file.is_open()) 273 250 { 274 251 COUT(1) << "An error occurred in Language.cc:" << std::endl; 275 COUT(1) << "Error: Couldn't open file " << getFileName( this->language_) << " to read the translated language entries!" << std::endl;276 ResetConfigValue(language_);252 COUT(1) << "Error: Couldn't open file " << getFileName(CoreSettings::getLanguage()) << " to read the translated language entries!" << std::endl; 253 CoreSettings::resetLanguage(); 277 254 COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl; 278 255 return; … … 288 265 289 266 // Check if the line is empty 290 if ( lineString.compare("") != 0)267 if ((lineString != "") && (lineString.size() > 0)) 291 268 { 292 269 unsigned int pos = lineString.find('='); … … 304 281 } 305 282 else 306 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->language_) << std::endl; 283 { 284 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(CoreSettings::getLanguage()) << std::endl; 285 } 307 286 } 308 287 } … … 330 309 331 310 // Iterate through the list an write the lines into the file 332 for ( Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)333 { 334 file << it->getLabel() << "=" << it->getDefault() << std::endl;311 for (std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 312 { 313 file << (*it).second->getLabel() << "=" << (*it).second->getDefault() << std::endl; 335 314 } 336 315
Note: See TracChangeset
for help on using the changeset viewer.