Changeset 871 for code/trunk/src/orxonox/core/Language.cc
- Timestamp:
- Mar 9, 2008, 4:44:36 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/Language.cc
r790 r871 26 26 */ 27 27 28 /* !28 /** 29 29 @file Language.cc 30 30 @brief Implementation of the Language and the LanguageEntry class. … … 50 50 51 51 this->fallbackEntry_ = fallbackEntry; 52 this-> translatedEntry_ = fallbackEntry; // Set the translation to the fallback entry, for the case that no translation gets assigned53 this->b TranslationSet_ = false;54 } 55 56 /** 57 @brief Sets the translation of the entry.58 @param translation The translation59 */ 60 void LanguageEntry::set Translation(const std::string& translation)52 this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned 53 this->bLocalisationSet_ = false; 54 } 55 56 /** 57 @brief Sets the localisation of the entry. 58 @param localisation The localisation 59 */ 60 void LanguageEntry::setLocalisation(const std::string& localisation) 61 61 { 62 62 // Check if the translation is more than just an empty string 63 if ( translation.compare("") != 0)64 { 65 this-> translatedEntry_ = translation;66 this->b TranslationSet_ = true;63 if (localisation.compare("") != 0) 64 { 65 this->localisedEntry_ = localisation; 66 this->bLocalisationSet_ = true; 67 67 } 68 68 else 69 this-> translatedEntry_ = this->fallbackEntry_;69 this->localisedEntry_ = this->fallbackEntry_; 70 70 } 71 71 … … 77 77 { 78 78 // If the default entry changes and the translation wasn't set yet, use the new default entry as translation 79 if (!this->b TranslationSet_)80 this-> translatedEntry_ = fallbackEntry;79 if (!this->bLocalisationSet_) 80 this->localisedEntry_ = fallbackEntry; 81 81 82 82 this->fallbackEntry_ = fallbackEntry; … … 94 94 95 95 this->defaultLanguage_ = "default"; 96 this->default Translation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";96 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; 97 97 98 98 // Read the default language file to create all known LanguageEntry objects … … 132 132 133 133 /** 134 @brief Creates a new LanguageEntry with a given nameand a given default entry.135 @param name The nameof the entry134 @brief Creates a new LanguageEntry with a given label and a given default entry. 135 @param label The label of the entry 136 136 @param entry The default entry 137 137 @return The created LanguageEntry object 138 138 */ 139 LanguageEntry* Language::createEntry(const LanguageEntry Name& name, const std::string& entry)140 { 141 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find( name);139 LanguageEntry* Language::createEntry(const LanguageEntryLabel& label, const std::string& entry) 140 { 141 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label); 142 142 143 143 // Make sure we don't create a duplicate entry … … 145 145 { 146 146 LanguageEntry* newEntry = new LanguageEntry(entry); 147 newEntry->set Name(name);148 this->languageEntries_[ name] = newEntry;147 newEntry->setLabel(label); 148 this->languageEntries_[label] = newEntry; 149 149 return newEntry; 150 150 } 151 151 152 COUT(2) << "Warning: Language entry " << name<< " is duplicate in " << getFileName(this->defaultLanguage_) << "!" << std::endl;152 COUT(2) << "Warning: Language entry " << label << " is duplicate in " << getFileName(this->defaultLanguage_) << "!" << std::endl; 153 153 return it->second; 154 154 } … … 156 156 /** 157 157 @brief Adds a new LanguageEntry, if it's not already existing. 158 @param name The nameof the entry158 @param label The label of the entry 159 159 @param entry The default entry 160 160 */ 161 void Language::addEntry(const LanguageEntry Name& name, const std::string& entry)162 { 163 COUT(5) << " Called addEntry with\n name: " << name<< "\n entry: " << entry << std::endl;164 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find( name);161 void Language::addEntry(const LanguageEntryLabel& label, const std::string& entry) 162 { 163 COUT(5) << "Language: Called addEntry with\n label: " << label << "\n entry: " << entry << std::endl; 164 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label); 165 165 if (it == this->languageEntries_.end()) 166 166 { 167 167 // The entry isn't available yet, meaning it's new, so create it 168 this->createEntry( name, entry);168 this->createEntry(label, entry); 169 169 } 170 170 else if (it->second->getDefault().compare(entry) == 0) … … 185 185 186 186 /** 187 @brief Returns the translation of a given entry.188 @param name The nameof the entry189 @return The translation190 */ 191 const std::string& Language::get Translation(const LanguageEntryName& name) const192 { 193 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find( name);187 @brief Returns the localisation of a given entry. 188 @param label The label of the entry 189 @return The localisation 190 */ 191 const std::string& Language::getLocalisation(const LanguageEntryLabel& label) const 192 { 193 std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.find(label); 194 194 if (it != this->languageEntries_.end()) 195 return it->second->get Translation();195 return it->second->getLocalisation(); 196 196 else 197 197 { 198 198 // Uh, oh, an undefined entry was requested: return the default string 199 COUT(2) << " Error: Language entry \"" << name<< "\" not found!" << std::endl;200 return this->default Translation_;199 COUT(2) << "Warning: Language entry \"" << label << "\" not found!" << std::endl; 200 return this->defaultLocalisation_; 201 201 } 202 202 } … … 230 230 if (!file.is_open()) 231 231 { 232 COUT(1) << "An error occurred in Language.cc:" << std::endl; 232 233 COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to read the default language entries!" << std::endl; 233 234 return; … … 259 260 260 261 /** 261 @brief Reads the language file of the configured language and assigns the translationsto the corresponding LanguageEntry object.262 @brief Reads the language file of the configured language and assigns the localisation to the corresponding LanguageEntry object. 262 263 */ 263 264 void Language::readTranslatedLanguageFile() … … 271 272 if (!file.is_open()) 272 273 { 274 COUT(1) << "An error occurred in Language.cc:" << std::endl; 273 275 COUT(1) << "Error: Couldn't open file " << getFileName(this->language_) << " to read the translated language entries!" << std::endl; 274 276 ResetConfigValue(language_); … … 297 299 // Check if the entry exists 298 300 if (it != this->languageEntries_.end()) 299 it->second->set Translation(lineString.substr(pos + 1));301 it->second->setLocalisation(lineString.substr(pos + 1)); 300 302 else 301 this->createEntry(lineString.substr(0, pos), this->default Translation_)->setTranslation(lineString.substr(pos + 1));303 this->createEntry(lineString.substr(0, pos), this->defaultLocalisation_)->setLocalisation(lineString.substr(pos + 1)); 302 304 } 303 305 else … … 314 316 void Language::writeDefaultLanguageFile() const 315 317 { 316 COUT(4) << " Write default language file." << std::endl;318 COUT(4) << "Language: Write default language file." << std::endl; 317 319 318 320 // Open the file … … 322 324 if (!file.is_open()) 323 325 { 326 COUT(1) << "An error occurred in Language.cc:" << std::endl; 324 327 COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to write the default language entries!" << std::endl; 325 328 return; … … 329 332 for (Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it) 330 333 { 331 file << it->get Name() << "=" << it->getDefault() << std::endl;334 file << it->getLabel() << "=" << it->getDefault() << std::endl; 332 335 } 333 336
Note: See TracChangeset
for help on using the changeset viewer.