Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File:
1 edited

Legend:

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

    r871 r1052  
    2828/**
    2929    @file Language.cc
    30     @brief Implementation of the Language and the LanguageEntry class.
     30    @brief Implementation of the Language and the LanguageEntry classes.
    3131*/
    3232
    3333#include <fstream>
    3434
    35 #include "CoreIncludes.h"
    3635#include "Language.h"
     36#include "CoreSettings.h"
    3737
    3838namespace orxonox
     
    4747    LanguageEntry::LanguageEntry(const std::string& fallbackEntry)
    4848    {
    49         RegisterRootObject(LanguageEntry);
    50 
    5149        this->fallbackEntry_ = fallbackEntry;
    5250        this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned
     
    6159    {
    6260        // Check if the translation is more than just an empty string
    63         if (localisation.compare("") != 0)
     61        if ((localisation != "") && (localisation.size() > 0))
    6462        {
    6563            this->localisedEntry_ = localisation;
     
    9189    Language::Language()
    9290    {
    93         RegisterRootObject(Language);
    94 
    9591        this->defaultLanguage_ = "default";
    9692        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    10197
    10298    /**
    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 configured
    110         this->readTranslatedLanguageFile();
    111     }
    112 
    113     /**
    11499        @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    115100        @return The reference to the only existing instance
     
    117102    Language& Language::getLanguage()
    118103    {
    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;
    131106    }
    132107
     
    244219
    245220            // Check if the line is empty
    246             if (lineString.compare("") != 0)
     221            if ((lineString != "") && (lineString.size() > 0))
    247222            {
    248223                unsigned int pos = lineString.find('=');
     
    252227                    this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1));
    253228                else
     229                {
    254230                    COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->defaultLanguage_) << std::endl;
     231                }
    255232            }
    256233        }
     
    264241    void Language::readTranslatedLanguageFile()
    265242    {
    266         COUT(4) << "Read translated language file (" << this->language_ << ")." << std::endl;
     243        COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl;
    267244
    268245        // Open the file
    269246        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);
    271248
    272249        if (!file.is_open())
    273250        {
    274251            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();
    277254            COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl;
    278255            return;
     
    288265
    289266            // Check if the line is empty
    290             if (lineString.compare("") != 0)
     267            if ((lineString != "") && (lineString.size() > 0))
    291268            {
    292269                unsigned int pos = lineString.find('=');
     
    304281                }
    305282                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                }
    307286            }
    308287        }
     
    330309
    331310        // 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;
    335314        }
    336315
Note: See TracChangeset for help on using the changeset viewer.