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::wstring> _names;
49  static std::vector<std::string> _rtl, _cjk;
50 
52  std::wstring loadString(const std::string &s) const;
53 public:
55  Language();
57  ~Language();
59  static std::string wstrToUtf8(const std::wstring& src);
61  static std::string wstrToCp(const std::wstring &src);
63  static std::string wstrToFs(const std::wstring &src);
65  static std::wstring utf8ToWstr(const std::string& src);
67  static std::wstring cpToWstr(const std::string& src);
69  static std::wstring fsToWstr(const std::string &src);
71  static void replace(std::string &str, const std::string &find, const std::string &replace);
73  static void replace(std::wstring &str, const std::wstring &find, const std::wstring &replace);
75  static void getList(std::vector<std::string> &files, std::vector<std::wstring> &names);
77  void load(const std::string &filename);
79  void load(ExtraStrings *strings);
81  std::string getId() const;
83  std::wstring getName() const;
85  void toHtml(const std::string &filename) const;
87  const LocalizedText &getString(const std::string &id) const;
89  LocalizedText getString(const std::string &id, unsigned n) const;
91  const LocalizedText &getString(const std::string &id, SoldierGender gender) const;
93  TextDirection getTextDirection() const;
95  TextWrapping getTextWrapping() const;
96 };
97 
98 }
static void replace(std::string &str, const std::string &find, const std::string &replace)
Replaces a substring.
Definition: Language.cpp:325
static std::wstring cpToWstr(const std::string &src)
Converts a local-codepage string to wide-string.
Definition: Language.cpp:283
void toHtml(const std::string &filename) const
Outputs the language to a HTML file.
Definition: Language.cpp:593
static std::wstring utf8ToWstr(const std::string &src)
Converts a UTF-8 string to wide-string.
Definition: Language.cpp:217
std::string getId() const
Gets the language&#39;s ID.
Definition: Language.cpp:467
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:624
A string that is already translated.
Definition: LocalizedText.h:43
Language()
Creates a blank language.
Definition: Language.cpp:47
For adding a set of extra strings to the game.
Definition: ExtraStrings.h:30
static std::string wstrToFs(const std::wstring &src)
Converts a wide-string to filesystem string.
Definition: Language.cpp:201
Contains strings used throughout the game for localization.
Definition: Language.h:39
static std::string wstrToCp(const std::wstring &src)
Converts a wide-string to local-codepage string.
Definition: Language.cpp:175
static std::string wstrToUtf8(const std::wstring &src)
Converts a wide-string to UTF-8.
Definition: Language.cpp:118
const LocalizedText & getString(const std::string &id) const
Get a localized text.
Definition: Language.cpp:487
static void getList(std::vector< std::string > &files, std::vector< std::wstring > &names)
Gets list of languages in the data directory.
Definition: Language.cpp:353
TextWrapping getTextWrapping() const
Gets the wrapping of text in this language.
Definition: Language.cpp:634
void load(const std::string &filename)
Loads the language from a YAML file.
Definition: Language.cpp:381
std::wstring getName() const
Gets the language&#39;s name.
Definition: Language.cpp:476
static std::wstring fsToWstr(const std::string &src)
Converts a filesystem string to wide-string.
Definition: Language.cpp:310
~Language()
Cleans up the language.
Definition: Language.cpp:106
Definition: BaseInfoState.cpp:40