Changeset 1036 for code/branches/core2/src/orxonox/core/Language.cc
- Timestamp:
- Apr 13, 2008, 1:36:45 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Language.cc
r1031 r1036 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" 37 #include "Co nfigValueIncludes.h"36 #include "CoreSettings.h" 38 37 39 38 namespace orxonox … … 48 47 LanguageEntry::LanguageEntry(const std::string& fallbackEntry) 49 48 { 50 RegisterRootObject(LanguageEntry);51 52 49 this->fallbackEntry_ = fallbackEntry; 53 50 this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned … … 92 89 Language::Language() 93 90 { 94 RegisterRootObject(Language);95 96 91 this->defaultLanguage_ = "default"; 97 92 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 102 97 103 98 /** 104 @brief Function to collect the SetConfigValue-macro calls.105 */106 void Language::setConfigValues()107 {108 SetConfigValue(language_, this->defaultLanguage_).description("The language of the ingame text");109 110 // Read the translation file after the language was configured111 this->readTranslatedLanguageFile();112 }113 114 /**115 99 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 116 100 @return The reference to the only existing instance … … 118 102 Language& Language::getLanguage() 119 103 { 120 // Use static variables to avoid conflicts while executing this code before main() 121 static Language theOnlyLanguageObject = Language(); 122 static bool bCreatingTheOnlyLanguageObject = true; 123 124 // This workaround is used to set a description of the own config value without creating an infinite recursion 125 if (bCreatingTheOnlyLanguageObject) 126 { 127 bCreatingTheOnlyLanguageObject = false; 128 theOnlyLanguageObject.setConfigValues(); 129 } 130 131 return theOnlyLanguageObject; 104 static Language instance = Language(); 105 return instance; 132 106 } 133 107 … … 267 241 void Language::readTranslatedLanguageFile() 268 242 { 269 COUT(4) << "Read translated language file (" << this->language_<< ")." << std::endl;243 COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl; 270 244 271 245 // Open the file 272 246 std::ifstream file; 273 file.open(getFileName( this->language_).c_str(), std::fstream::in);247 file.open(getFileName(CoreSettings::getLanguage()).c_str(), std::fstream::in); 274 248 275 249 if (!file.is_open()) 276 250 { 277 251 COUT(1) << "An error occurred in Language.cc:" << std::endl; 278 COUT(1) << "Error: Couldn't open file " << getFileName( this->language_) << " to read the translated language entries!" << std::endl;279 ResetConfigValue(language_);252 COUT(1) << "Error: Couldn't open file " << getFileName(CoreSettings::getLanguage()) << " to read the translated language entries!" << std::endl; 253 CoreSettings::resetLanguage(); 280 254 COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl; 281 255 return; … … 308 282 else 309 283 { 310 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName( this->language_) << std::endl;284 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(CoreSettings::getLanguage()) << std::endl; 311 285 } 312 286 } … … 335 309 336 310 // Iterate through the list an write the lines into the file 337 for ( Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)338 { 339 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; 340 314 } 341 315
Note: See TracChangeset
for help on using the changeset viewer.