Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2008, 4:44:36 PM (16 years ago)
Author:
landauf
Message:

merged core branch to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/core/Language.cc

    r790 r871  
    2626 */
    2727
    28 /*!
     28/**
    2929    @file Language.cc
    3030    @brief Implementation of the Language and the LanguageEntry class.
     
    5050
    5151        this->fallbackEntry_ = fallbackEntry;
    52         this->translatedEntry_ = fallbackEntry; // Set the translation to the fallback entry, for the case that no translation gets assigned
    53         this->bTranslationSet_ = false;
    54     }
    55 
    56     /**
    57         @brief Sets the translation of the entry.
    58         @param translation The translation
    59     */
    60     void LanguageEntry::setTranslation(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)
    6161    {
    6262        // Check if the translation is more than just an empty string
    63         if (translation.compare("") != 0)
    64         {
    65             this->translatedEntry_ = translation;
    66             this->bTranslationSet_ = true;
     63        if (localisation.compare("") != 0)
     64        {
     65            this->localisedEntry_ = localisation;
     66            this->bLocalisationSet_ = true;
    6767        }
    6868        else
    69             this->translatedEntry_ = this->fallbackEntry_;
     69            this->localisedEntry_ = this->fallbackEntry_;
    7070    }
    7171
     
    7777    {
    7878        // If the default entry changes and the translation wasn't set yet, use the new default entry as translation
    79         if (!this->bTranslationSet_)
    80             this->translatedEntry_ = fallbackEntry;
     79        if (!this->bLocalisationSet_)
     80            this->localisedEntry_ = fallbackEntry;
    8181
    8282        this->fallbackEntry_ = fallbackEntry;
     
    9494
    9595        this->defaultLanguage_ = "default";
    96         this->defaultTranslation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     96        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
    9797
    9898        // Read the default language file to create all known LanguageEntry objects
     
    132132
    133133    /**
    134         @brief Creates a new LanguageEntry with a given name and a given default entry.
    135         @param name The name of the entry
     134        @brief Creates a new LanguageEntry with a given label and a given default entry.
     135        @param label The label of the entry
    136136        @param entry The default entry
    137137        @return The created LanguageEntry object
    138138    */
    139     LanguageEntry* Language::createEntry(const LanguageEntryName& 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);
    142142
    143143        // Make sure we don't create a duplicate entry
     
    145145        {
    146146            LanguageEntry* newEntry = new LanguageEntry(entry);
    147             newEntry->setName(name);
    148             this->languageEntries_[name] = newEntry;
     147            newEntry->setLabel(label);
     148            this->languageEntries_[label] = newEntry;
    149149            return newEntry;
    150150        }
    151151
    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;
    153153        return it->second;
    154154    }
     
    156156    /**
    157157        @brief Adds a new LanguageEntry, if it's not already existing.
    158         @param name The name of the entry
     158        @param label The label of the entry
    159159        @param entry The default entry
    160160    */
    161     void Language::addEntry(const LanguageEntryName& 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);
    165165        if (it == this->languageEntries_.end())
    166166        {
    167167            // The entry isn't available yet, meaning it's new, so create it
    168             this->createEntry(name, entry);
     168            this->createEntry(label, entry);
    169169        }
    170170        else if (it->second->getDefault().compare(entry) == 0)
     
    185185
    186186    /**
    187         @brief Returns the translation of a given entry.
    188         @param name The name of the entry
    189         @return The translation
    190     */
    191     const std::string& Language::getTranslation(const LanguageEntryName& name) const
    192     {
    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);
    194194        if (it != this->languageEntries_.end())
    195             return it->second->getTranslation();
     195            return it->second->getLocalisation();
    196196        else
    197197        {
    198198            // 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->defaultTranslation_;
     199            COUT(2) << "Warning: Language entry \"" << label << "\" not found!" << std::endl;
     200            return this->defaultLocalisation_;
    201201        }
    202202    }
     
    230230        if (!file.is_open())
    231231        {
     232            COUT(1) << "An error occurred in Language.cc:" << std::endl;
    232233            COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to read the default language entries!" << std::endl;
    233234            return;
     
    259260
    260261    /**
    261         @brief Reads the language file of the configured language and assigns the translations to the corresponding LanguageEntry object.
     262        @brief Reads the language file of the configured language and assigns the localisation to the corresponding LanguageEntry object.
    262263    */
    263264    void Language::readTranslatedLanguageFile()
     
    271272        if (!file.is_open())
    272273        {
     274            COUT(1) << "An error occurred in Language.cc:" << std::endl;
    273275            COUT(1) << "Error: Couldn't open file " << getFileName(this->language_) << " to read the translated language entries!" << std::endl;
    274276            ResetConfigValue(language_);
     
    297299                    // Check if the entry exists
    298300                    if (it != this->languageEntries_.end())
    299                         it->second->setTranslation(lineString.substr(pos + 1));
     301                        it->second->setLocalisation(lineString.substr(pos + 1));
    300302                    else
    301                         this->createEntry(lineString.substr(0, pos), this->defaultTranslation_)->setTranslation(lineString.substr(pos + 1));
     303                        this->createEntry(lineString.substr(0, pos), this->defaultLocalisation_)->setLocalisation(lineString.substr(pos + 1));
    302304                }
    303305                else
     
    314316    void Language::writeDefaultLanguageFile() const
    315317    {
    316         COUT(4) << "Write default language file." << std::endl;
     318        COUT(4) << "Language: Write default language file." << std::endl;
    317319
    318320        // Open the file
     
    322324        if (!file.is_open())
    323325        {
     326            COUT(1) << "An error occurred in Language.cc:" << std::endl;
    324327            COUT(1) << "Error: Couldn't open file " << getFileName(this->defaultLanguage_) << " to write the default language entries!" << std::endl;
    325328            return;
     
    329332        for (Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)
    330333        {
    331             file << it->getName() << "=" << it->getDefault() << std::endl;
     334            file << it->getLabel() << "=" << it->getDefault() << std::endl;
    332335        }
    333336
Note: See TracChangeset for help on using the changeset viewer.