Changeset 838
- Timestamp:
- Feb 27, 2008, 12:54:00 AM (17 years ago)
- Location:
- code/branches/core/src/orxonox/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/ConfigValueContainer.cc
r826 r838 959 959 std::string ConfigValueContainer::getDescription() const 960 960 { 961 return Language::getLanguage().get Translation(this->description_);961 return Language::getLanguage().getLocalisation(this->description_); 962 962 } 963 963 } -
code/branches/core/src/orxonox/core/ConfigValueContainer.h
r826 r838 150 150 151 151 bool bAddedDescription_; //!< True if a description was added 152 LanguageEntry Name description_;//!< The description152 LanguageEntryLabel description_; //!< The description 153 153 }; 154 154 } -
code/branches/core/src/orxonox/core/CorePrereqs.h
r826 r838 65 65 namespace orxonox 66 66 { 67 typedef std::string LanguageEntry Name;67 typedef std::string LanguageEntryLabel; 68 68 69 69 class ArgReader; -
code/branches/core/src/orxonox/core/Language.cc
r820 r838 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->setName( name);148 this->languageEntries_[ name] = newEntry;147 newEntry->setName(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) << "Language: 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) << "Warning: 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 } … … 260 260 261 261 /** 262 @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. 263 263 */ 264 264 void Language::readTranslatedLanguageFile() … … 299 299 // Check if the entry exists 300 300 if (it != this->languageEntries_.end()) 301 it->second->set Translation(lineString.substr(pos + 1));301 it->second->setLocalisation(lineString.substr(pos + 1)); 302 302 else 303 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)); 304 304 } 305 305 else -
code/branches/core/src/orxonox/core/Language.h
r826 r838 30 30 @brief Definition of the Language and the LanguageEntry class. 31 31 32 The Language class is used, to get a translation of a string in the configured language.33 The string is identified by another string, the nameof the entry.32 The Language class is used, to get a localisation of a string in the configured language. 33 The string is identified by another string, the label of the entry. 34 34 If the translation in the configured language isn't available, the default entry, defined in the code, is used. 35 35 36 36 Usage: 37 37 - Set the entry with the default string: 38 Language::getLanguage()->addEntry(" nameof the entry", "the string to translate");38 Language::getLanguage()->addEntry("label of the entry", "the string to translate"); 39 39 40 - Get the translation of the entry in the configured language:41 std::cout << Language::getLanguage()->get Translation("name of the entry") << std::endl;40 - Get the localisation of the entry in the configured language: 41 std::cout << Language::getLanguage()->getLocalisation("name of the entry") << std::endl; 42 42 */ 43 43 … … 61 61 public: 62 62 explicit LanguageEntry(const std::string& fallbackEntry); 63 void set Translation(const std::string& translation);63 void setLocalisation(const std::string& localisation); 64 64 void setDefault(const std::string& fallbackEntry); 65 65 66 66 /** 67 @brief Returns the translated entry in the configured language.67 @brief Returns the localised entry in the configured language. 68 68 @return The translated entry 69 69 */ 70 inline const std::string& get Translation()71 { return this-> translatedEntry_; }70 inline const std::string& getLocalisation() 71 { return this->localisedEntry_; } 72 72 73 73 /** … … 80 80 private: 81 81 std::string fallbackEntry_; //!< The default entry: Used, if no translation is available or no language configured 82 std::string translatedEntry_; //!< The translated entry in the configured language83 bool b TranslationSet_;//!< True if the translation was set82 std::string localisedEntry_; //!< The localised entry in the configured language 83 bool bLocalisationSet_; //!< True if the translation was set 84 84 }; 85 85 template class _CoreExport orxonox::ClassIdentifier<LanguageEntry>; … … 99 99 static Language& getLanguage(); 100 100 void setConfigValues(); 101 void addEntry(const LanguageEntry Name& name, const std::string& entry);102 const std::string& get Translation(const LanguageEntryName& name) const;101 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 102 const std::string& getLocalisation(const LanguageEntryLabel& label) const; 103 103 104 104 private: … … 111 111 void writeDefaultLanguageFile() const; 112 112 static const std::string getFileName(const std::string& language); 113 LanguageEntry* createEntry(const LanguageEntry Name& name, const std::string& entry);113 LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry); 114 114 115 115 std::string language_; //!< The configured language 116 116 std::string defaultLanguage_; //!< The default language 117 std::string default Translation_;//!< The returned string, if an entry unavailable entry is requested118 std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their name117 std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested 118 std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels 119 119 }; 120 120 template class _CoreExport orxonox::ClassIdentifier<Language>;
Note: See TracChangeset
for help on using the changeset viewer.