Orxonox  0.0.5 Codename: Arcturus
Language.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
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 
89 #ifndef _Language_H__
90 #define _Language_H__
91 
92 #include "CorePrereqs.h"
93 
94 #include <map>
95 #include <string>
96 #include <cassert>
97 #include "util/Singleton.h"
98 
99 namespace orxonox
100 {
101  // ###############################
102  // ### LanguageEntry ###
103  // ###############################
110  {
111  public:
112  explicit LanguageEntry(const std::string& fallbackEntry);
113  void setLocalisation(const std::string& localisation);
114  void setDefault(const std::string& fallbackEntry);
115 
120  inline const std::string& getLocalisation()
121  { return this->localisedEntry_; }
122 
127  inline const std::string& getDefault()
128  { return this->fallbackEntry_; }
129 
134  inline void setLabel(const LanguageEntryLabel& label)
135  { this->label_ = label; }
136 
141  inline const LanguageEntryLabel& getLabel() const
142  { return this->label_; }
143 
144  private:
149  };
150 
151 
152  // ###############################
153  // ### Language ###
154  // ###############################
160  class _CoreExport Language : public Singleton<Language>
161  {
162  friend class Singleton<Language>;
163  friend class CoreConfig;
164 
165  public:
166  Language();
167  ~Language();
168 
169  void addEntry(const LanguageEntryLabel& label, const std::string& entry);
170  const std::string& getLocalisation(const LanguageEntryLabel& label, bool bError = true) const;
171 
172  private:
173  // non-copyable:
174  Language(const Language&) = delete;
175  Language& operator=(const Language&) = delete;
176 
177  void readDefaultLanguageFile();
178  bool readTranslatedLanguageFile(const std::string& language);
179  void writeDefaultLanguageFile() const;
180  static std::string getFilename(const std::string& language);
181  LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry);
182 
185  std::map<std::string, LanguageEntry*> languageEntries_;
186 
188  };
189 
191  inline void AddLanguageEntry(const LanguageEntryLabel& label, const std::string& fallbackString)
192  {
193  Language::getInstance().addEntry(label, fallbackString);
194  }
195 
197  inline const std::string& GetLocalisation(const LanguageEntryLabel& label)
198  {
199  return Language::getInstance().getLocalisation(label);
200  }
201 
204  {
205  return Language::getInstance().getLocalisation(label, false);
206  }
207 }
208 
209 #endif /* _Language_H__ */
The LanguageEntry class stores the default- and the translated string of a given entry in the languag...
Definition: Language.h:109
std::string defaultLanguage_
The default language.
Definition: Language.h:183
void AddLanguageEntry(const LanguageEntryLabel &label, const std::string &fallbackString)
Shortcut function for Language::addEntry.
Definition: Language.h:191
std::string fallbackEntry_
The default entry: Used, if no translation is available or no language configured.
Definition: Language.h:146
const LanguageEntryLabel & getLabel() const
Returns the label of this entry.
Definition: Language.h:141
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
void addEntry(const LanguageEntryLabel &label, const std::string &entry)
Adds a new LanguageEntry, if it&#39;s not already existing.
Definition: Language.cc:141
std::string localisedEntry_
The localised entry in the configured language.
Definition: Language.h:147
const std::string & getDefault()
Returns the default entry.
Definition: Language.h:127
The Language class manges the language files and entries and stores the LanguageEntry objects in a ma...
Definition: Language.h:160
Definition: CoreConfig.h:38
const std::string & getLocalisation()
Returns the localised entry in the configured language.
Definition: Language.h:120
std::string defaultLocalisation_
The returned string, if an entry unavailable entry is requested.
Definition: Language.h:184
void setLabel(const LanguageEntryLabel &label)
Sets the label of this entry.
Definition: Language.h:134
std::map< std::string, LanguageEntry * > languageEntries_
A map to store all LanguageEntry objects and their labels.
Definition: Language.h:185
Base for singleton classes.
Definition: Singleton.h:114
LanguageEntryLabel label_
The label of the entry.
Definition: Language.h:145
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
bool bLocalisationSet_
True if the translation was set.
Definition: Language.h:148
#define _CoreExport
Definition: CorePrereqs.h:61
static Language * singletonPtr_s
Definition: Language.h:187
const std::string & getLocalisation(const LanguageEntryLabel &label, bool bError=true) const
Returns the localisation of a given entry.
Definition: Language.cc:172
Definition of the Singleton template that is used as base class for classes that allow only one insta...
std::string LanguageEntryLabel
Definition: CorePrereqs.h:141
static Language & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
const std::string & GetLocalisation(const LanguageEntryLabel &label)
Shortcut function for Language::getLocalisation.
Definition: Language.h:197
const std::string & GetLocalisation_noerror(const LanguageEntryLabel &label)
Shortcut function for Language::getLocalisation without printing an error in case the label doesn&#39;t e...
Definition: Language.h:203