Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/Language.h @ 1417

Last change on this file since 1417 was 1313, checked in by landauf, 16 years ago
  • implemented Shell, but not yet linked with the graphical console
  • added new features (cursor, OIS::KeyCode listener) to InputBuffer
  • changed some includes to avoid circular header-dependencies in OrxonoxClass and Shell
File size: 5.3 KB
RevLine 
[704]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[704]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[871]29/**
[720]30    @file Language.h
31    @brief Definition of the Language and the LanguageEntry class.
32
[871]33    The Language class is used, to get a localisation of a string in the configured language.
34    The string is identified by another string, the label of the entry.
[720]35    If the translation in the configured language isn't available, the default entry, defined in the code, is used.
36
37    Usage:
38     - Set the entry with the default string:
[871]39       Language::getLanguage()->addEntry("label of the entry", "the string to translate");
[720]40
[871]41     - Get the localisation of the entry in the configured language:
42       std::cout << Language::getLanguage()->getLocalisation("name of the entry") << std::endl;
[720]43*/
44
[704]45#ifndef _Language_H__
46#define _Language_H__
47
[1062]48#include "CorePrereqs.h"
49
[704]50#include <map>
[715]51#include <string>
[704]52
[871]53#define AddLanguageEntry(label, fallbackstring) \
54    orxonox::Language::getLanguage().addEntry(label, fallbackstring)
55
56#define GetLocalisation(label) \
57    orxonox::Language::getLanguage().getLocalisation(label)
58
59
[704]60namespace orxonox
61{
[871]62    // ###############################
63    // ###      LanguageEntry      ###
64    // ###############################
[720]65    //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file.
[1052]66    class _CoreExport LanguageEntry
[704]67    {
68        public:
[715]69            explicit LanguageEntry(const std::string& fallbackEntry);
[871]70            void setLocalisation(const std::string& localisation);
[715]71            void setDefault(const std::string& fallbackEntry);
[704]72
[728]73            /**
[871]74              @brief Returns the localised entry in the configured language.
[728]75              @return The translated entry
76            */
[871]77            inline const std::string& getLocalisation()
78                { return this->localisedEntry_; }
[704]79
[728]80            /**
81              @brief Returns the default entry.
82              @return The default entry
83            */
[715]84            inline const std::string& getDefault()
[704]85                { return this->fallbackEntry_; }
86
[871]87            /**
88                @brief Sets the label of this entry.
89                @param label The label
90            */
91            inline void setLabel(const LanguageEntryLabel& label)
92                { this->label_ = label; }
93
94            /**
95                @brief Returns the label of this entry.
96                @return The label
97            */
98            inline const LanguageEntryLabel& getLabel() const
99                { return this->label_; }
100
[704]101        private:
[871]102            LanguageEntryLabel label_;              //!< The label of the entry
103            std::string fallbackEntry_;             //!< The default entry: Used, if no translation is available or no language configured
104            std::string localisedEntry_;            //!< The localised entry in the configured language
105            bool bLocalisationSet_;                 //!< True if the translation was set
[704]106    };
107
[871]108
109    // ###############################
110    // ###         Language        ###
111    // ###############################
[720]112    //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map.
[1052]113    class _CoreExport Language
[704]114    {
[1052]115        friend class CoreSettings;
[737]116
[704]117        public:
118            static Language& getLanguage();
[871]119            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
120            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
[704]121
122        private:
123            Language();
[1064]124            Language(const Language& language);     // don't copy
[704]125            virtual ~Language() {};                 // don't delete
126
127            void readDefaultLanguageFile();
128            void readTranslatedLanguageFile();
129            void writeDefaultLanguageFile() const;
[715]130            static const std::string getFileName(const std::string& language);
[871]131            LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry);
[704]132
[720]133            std::string defaultLanguage_;                           //!< The default language
[871]134            std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
135            std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
[704]136    };
137}
138
139#endif /* _Language_H__ */
Note: See TracBrowser for help on using the repository browser.