OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "LocalizedText.h"
27 #include "../Savegame/Soldier.h"
28 
29 namespace OpenXcom
30 {
31 enum TextDirection { DIRECTION_LTR, DIRECTION_RTL };
32 enum TextWrapping { WRAP_WORDS, WRAP_LETTERS };
33 
34 class TextList;
35 class ExtraStrings;
36 class LanguagePlurality;
37 
42 class Language
43 {
44 private:
45  std::string _id;
46  std::map<std::string, LocalizedText> _strings;
47  LanguagePlurality *_handler;
48  TextDirection _direction;
49  TextWrapping _wrap;
50 
51  static std::map<std::string, std::wstring> _names;
52  static std::vector<std::string> _rtl, _cjk;
53 
55  std::wstring loadString(const std::string &s) const;
56 public:
58  Language();
60  ~Language();
62  static std::string wstrToUtf8(const std::wstring& src);
64  static std::string wstrToCp(const std::wstring &src);
66  static std::string wstrToFs(const std::wstring &src);
68  static std::wstring utf8ToWstr(const std::string& src);
70  static std::wstring cpToWstr(const std::string& src);
72  static std::wstring fsToWstr(const std::string &src);
74  static void replace(std::string &str, const std::string &find, const std::string &replace);
76  static void replace(std::wstring &str, const std::wstring &find, const std::wstring &replace);
78  static void getList(std::vector<std::string> &files, std::vector<std::wstring> &names);
80  void load(const std::string &filename, ExtraStrings *extras);
82  std::string getId() const;
84  std::wstring getName() const;
86  void toHtml(const std::string &filename) const;
88  const LocalizedText &getString(const std::string &id) const;
90  LocalizedText getString(const std::string &id, unsigned n) const;
92  const LocalizedText &getString(const std::string &id, SoldierGender gender) const;
94  TextDirection getTextDirection() const;
96  TextWrapping getTextWrapping() const;
97 };
98 
99 }
100 
101 #endif
static void replace(std::string &str, const std::string &find, const std::string &replace)
Replaces a substring.
Definition: Language.cpp:317
static std::wstring cpToWstr(const std::string &src)
Converts a local-codepage string to wide-string.
Definition: Language.cpp:275
static std::wstring utf8ToWstr(const std::string &src)
Converts a UTF-8 string to wide-string.
Definition: Language.cpp:209
TextWrapping getTextWrapping() const
Gets the wrapping of text in this language.
Definition: Language.cpp:583
std::wstring getName() const
Gets the language's name.
Definition: Language.cpp:453
This class is the interface used to find plural forms for the different languages.
Definition: LanguagePlurality.h:32
void load(const std::string &filename, ExtraStrings *extras)
Loads the language from a YAML file.
Definition: Language.cpp:374
A string that is already translated.
Definition: LocalizedText.h:45
Language()
Creates a blank language.
Definition: Language.cpp:48
For adding a set of extra strings to the game.
Definition: ExtraStrings.h:32
static std::string wstrToFs(const std::wstring &src)
Converts a wide-string to filesystem string.
Definition: Language.cpp:193
Contains strings used throughout the game for localization.
Definition: Language.h:42
static std::string wstrToCp(const std::wstring &src)
Converts a wide-string to local-codepage string.
Definition: Language.cpp:167
static std::string wstrToUtf8(const std::wstring &src)
Converts a wide-string to UTF-8.
Definition: Language.cpp:110
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
std::string getId() const
Gets the language's ID.
Definition: Language.cpp:444
void toHtml(const std::string &filename) const
Outputs the language to a HTML file.
Definition: Language.cpp:542
TextDirection getTextDirection() const
Gets the direction of text in this language.
Definition: Language.cpp:573
static std::wstring fsToWstr(const std::string &src)
Converts a filesystem string to wide-string.
Definition: Language.cpp:302
~Language()
Cleans up the language.
Definition: Language.cpp:98
const LocalizedText & getString(const std::string &id) const
Get a localized text.
Definition: Language.cpp:464