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 38 /** 39 * Contains strings used throughout the game for localization. 40 * Languages are just a set of strings identified by an ID string. 41 */ 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 54 /// Parses a text string loaded from an external file. 55 std::wstring loadString(const std::string &s) const; 56 public: 57 /// Creates a blank language. 58 Language(); 59 /// Cleans up the language. 60 ~Language(); 61 /// Converts a wide-string to UTF-8. 62 static std::string wstrToUtf8(const std::wstring& src); 63 /// Converts a wide-string to local-codepage string. 64 static std::string wstrToCp(const std::wstring &src); 65 /// Converts a wide-string to filesystem string. 66 static std::string wstrToFs(const std::wstring &src); 67 /// Converts a UTF-8 string to wide-string. 68 static std::wstring utf8ToWstr(const std::string& src); 69 /// Converts a local-codepage string to wide-string. 70 static std::wstring cpToWstr(const std::string& src); 71 /// Converts a filesystem string to wide-string. 72 static std::wstring fsToWstr(const std::string &src); 73 /// Replaces a substring. 74 static void replace(std::string &str, const std::string &find, const std::string &replace); 75 /// Replaces a substring. 76 static void replace(std::wstring &str, const std::wstring &find, const std::wstring &replace); 77 /// Gets list of languages in the data directory. 78 static void getList(std::vector<std::string> &files, std::vector<std::wstring> &names); 79 /// Loads the language from a YAML file. 80 void load(const std::string &filename, ExtraStrings *extras); 81 /// Gets the language's ID. 82 std::string getId() const; 83 /// Gets the language's name. 84 std::wstring getName() const; 85 /// Outputs the language to a HTML file. 86 void toHtml(const std::string &filename) const; 87 /// Get a localized text. 88 const LocalizedText &getString(const std::string &id) const; 89 /// Get a quantity-depended localized text. 90 LocalizedText getString(const std::string &id, unsigned n) const; 91 /// Get a gender-depended localized text. 92 const LocalizedText &getString(const std::string &id, SoldierGender gender) const; 93 /// Gets the direction of text in this language. 94 TextDirection getTextDirection() const; 95 /// Gets the wrapping of text in this language. 96 TextWrapping getTextWrapping() const; 97 }; 98 99 } 100 101 #endif 102