OpenXcom  1.0
Open-source clone of the original X-Com
Language.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *e
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_LANGUAGE_H
20 #define OPENXCOM_LANGUAGE_H
21 
22 #include <map>
23 #include <vector>
24 #include <string>
25 #include <yaml-cpp/yaml.h>
26 #include <algorithm>
27 #include "LocalizedText.h"
28 #include "../Savegame/Soldier.h"
29 
30 namespace OpenXcom
31 {
32 enum TextDirection { DIRECTION_LTR, DIRECTION_RTL };
33 enum TextWrapping { WRAP_WORDS, WRAP_LETTERS };
34 
35 class TextList;
36 class ExtraStrings;
37 class LanguagePlurality;
38 
43 class Language
44 {
45 private:
46  std::string _id;
47  std::map<std::string, LocalizedText> _strings;
48  LanguagePlurality *_handler;
49  TextDirection _direction;
50  TextWrapping _wrap;
51 
52  static std::map<std::string, std::wstring> _names;
53  static std::vector<std::string> _rtl, _cjk;
54 
56  std::wstring loadString(const std::string &s) const;
57 public:
59  Language();
61  ~Language();
63  static std::string wstrToUtf8(const std::wstring& src);
65  static std::string wstrToCp(const std::wstring &src);
67  static std::string wstrToFs(const std::wstring &src);
69  static std::wstring utf8ToWstr(const std::string& src);
71  static std::wstring cpToWstr(const std::string& src);
73  static std::wstring fsToWstr(const std::string &src);
75  static void replace(std::string &str, const std::string &find, const std::string &replace);
77  static void replace(std::wstring &str, const std::wstring &find, const std::wstring &replace);
79  static void getList(std::vector<std::string> &files, std::vector<std::wstring> &names);
81  void load(const std::string &filename, ExtraStrings *extras);
83  std::string getId() const;
85  std::wstring getName() const;
87  void toHtml(const std::string &filename) const;
89  const LocalizedText &getString(const std::string &id) const;
91  LocalizedText getString(const std::string &id, unsigned n) const;
93  const LocalizedText &getString(const std::string &id, SoldierGender gender) const;
95  TextDirection getTextDirection() const;
97  TextWrapping getTextWrapping() const;
98 };
99 
100 }
101 
102 #endif
For adding a set of extra strings to the game.
Definition: ExtraStrings.h:33
Contains strings used throughout the game for localization.
Definition: Language.h:44
std::wstring getName() const
Gets the language's name.
Definition: Language.cpp:453
Language()
Creates a blank language.
Definition: Language.cpp:48
void load(const std::string &filename, ExtraStrings *extras)
Loads the language from a YAML file.
Definition: Language.cpp:374
static void getList(std::vector< std::string > &files, std::vector< std::wstring > &names)
Gets list of languages in the data directory.
Definition: Language.cpp:345
static std::string wstrToUtf8(const std::wstring &src)
Converts a wide-string to UTF-8.
Definition: Language.cpp:110
const LocalizedText & getString(const std::string &id) const
Get a localized text.
Definition: Language.cpp:464
static std::wstring utf8ToWstr(const std::string &src)
Converts a UTF-8 string to wide-string.
Definition: Language.cpp:209
TextDirection getTextDirection() const
Gets the direction of text in this language.
Definition: Language.cpp:573
void toHtml(const std::string &filename) const
Outputs the language to a HTML file.
Definition: Language.cpp:542
std::string getId() const
Gets the language's ID.
Definition: Language.cpp:444
static void replace(std::string &str, const std::string &find, const std::string &replace)
Replaces a substring.
Definition: Language.cpp:317
static std::string wstrToCp(const std::wstring &src)
Converts a wide-string to local-codepage string.
Definition: Language.cpp:167
TextWrapping getTextWrapping() const
Gets the wrapping of text in this language.
Definition: Language.cpp:583
static std::wstring fsToWstr(const std::string &src)
Converts a filesystem string to wide-string.
Definition: Language.cpp:302
static std::wstring cpToWstr(const std::string &src)
Converts a local-codepage string to wide-string.
Definition: Language.cpp:275
~Language()
Cleans up the language.
Definition: Language.cpp:98
static std::string wstrToFs(const std::wstring &src)
Converts a wide-string to filesystem string.
Definition: Language.cpp:193
This class is the interface used to find plural forms for the different languages.
Definition: LanguagePlurality.h:33
A string that is already translated.
Definition: LocalizedText.h:46
COPYING:
Definition: BaseInfoState.cpp:41