OpenXcom  1.0
Open-source clone of the original X-Com
Language.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *e
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <map>
21 #include <vector>
22 #include <string>
23 #include "LocalizedText.h"
24 #include "../Savegame/Soldier.h"
25 
26 namespace OpenXcom
27 {
28 enum TextDirection { DIRECTION_LTR, DIRECTION_RTL };
29 enum TextWrapping { WRAP_WORDS, WRAP_LETTERS };
30 
31 class TextList;
32 class ExtraStrings;
33 class LanguagePlurality;
34 
39 class Language
40 {
41 private:
42  std::string _id;
43  std::map<std::string, LocalizedText> _strings;
44  LanguagePlurality *_handler;
45  TextDirection _direction;
46  TextWrapping _wrap;
47 
48  static std::map<std::string, std::string> _names;
49  static std::vector<std::string> _rtl, _cjk;
50 
52  std::string loadString(const std::string &s) const;
54  void load(const std::string &filename);
55 public:
57  Language();
59  ~Language();
61  static void getList(std::vector<std::string> &files, std::vector<std::string> &names);
63  void loadFile(const std::string &filename);
65  void loadRule(const std::map<std::string, ExtraStrings*> &extraStrings, const std::string &id);
67  std::string getId() const;
69  std::string getName() const;
71  void toHtml(const std::string &filename) const;
73  const LocalizedText &getString(const std::string &id) const;
75  LocalizedText getString(const std::string &id, unsigned n) const;
77  const LocalizedText &getString(const std::string &id, SoldierGender gender) const;
79  TextDirection getTextDirection() const;
81  TextWrapping getTextWrapping() const;
82 };
83 
84 }
void toHtml(const std::string &filename) const
Outputs the language to a HTML file.
Definition: Language.cpp:381
std::string getId() const
Gets the language&#39;s ID.
Definition: Language.cpp:255
This class is the interface used to find plural forms for the different languages.
Definition: LanguagePlurality.h:30
TextDirection getTextDirection() const
Gets the direction of text in this language.
Definition: Language.cpp:412
A string that is already translated.
Definition: LocalizedText.h:43
Language()
Creates a blank language.
Definition: Language.cpp:42
static void getList(std::vector< std::string > &files, std::vector< std::string > &names)
Gets list of languages in the data directory.
Definition: Language.cpp:111
Contains strings used throughout the game for localization.
Definition: Language.h:39
const LocalizedText & getString(const std::string &id) const
Get a localized text.
Definition: Language.cpp:275
std::string getName() const
Gets the language&#39;s name.
Definition: Language.cpp:264
TextWrapping getTextWrapping() const
Gets the wrapping of text in this language.
Definition: Language.cpp:422
void loadRule(const std::map< std::string, ExtraStrings *> &extraStrings, const std::string &id)
Loads the language from a ruleset file.
Definition: Language.cpp:224
void loadFile(const std::string &filename)
Loads the language from an external file.
Definition: Language.cpp:204
~Language()
Cleans up the language.
Definition: Language.cpp:100
Definition: BaseInfoState.cpp:40