1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 ////////////////////////////////////////////////////////////////////////////////
20 //
21 //  File:   language.h
22 //  Date:   07-10-01
23 //  Author: JCK
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26 //  Description:
27 //  This class handles the support for different language packs in XML-Format.
28 ////////////////////////////////////////////////////////////////////////////////
29 
30 #ifndef utility_languageH
31 #define utility_languageH
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #define LANGUAGE_FILE_FOLDER cSettings::getInstance().getLangPath()
36 #define LANGUAGE_FILE_NAME   "lang_"
37 #define LANGUAGE_FILE_EXT    ".xml"
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 // XML-Node paths
41 
42 // With nullptr as ending sign
43 #define XNP_MAX_LANG_FILE "MAX_Language_File", nullptr
44 #define XNP_MAX_LANG_FILE_FOOTER_AUTHOR "MAX_Language_File", "Footer", "Author", nullptr
45 #define XNP_MAX_LANG_FILE_FOOTER_AUTHOR_EDITOR "MAX_Language_File", "Footer", "Author", "Editor", nullptr
46 #define XNP_MAX_LANG_FILE_FOOTER_GAMEVERSION "MAX_Language_File", "Footer", "Game_Version", nullptr
47 #define XNP_MAX_LANG_FILE_TEXT "MAX_Language_File", "Text", nullptr
48 #define XNP_MAX_LANG_FILE_GRAPHIC "MAX_Language_File", "Graphic", nullptr
49 #define XNP_MAX_LANG_FILE_SPEECH "MAX_Language_File", "Speech", nullptr
50 
51 // Without nullptr as ending sign. Do not forget it in parameter list !
52 #define XNP_MAX_LANG_FILE_TEXT_MAIN "MAX_Language_File", "Text", "Main"
53 #define XNP_MAX_LANG_FILE_TEXT_ERROR_MSG "MAX_Language_File", "Text", "Error_Messages"
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #include <map>
58 #include <string>
59 #include <vector>
60 #include "defines.h"
61 #include "tinyxml2.h"
62 
63 class cLanguage
64 {
65 public:
66 	cLanguage();
67 
68 	const std::string& GetCurrentLanguage() const;
69 	int         SetCurrentLanguage (const std::string& szLanguageCode);
70 	std::string i18n (const std::string& szInputText);
71 	// Translation with replace %s
72 	std::string i18n (const std::string& szMainText, const std::string& szInsertText);
73 	int         ReadLanguagePack();
74 	int         CheckCurrentLanguagePack (bool bInsertMissingEntries);
75 	std::vector<std::string> getAvailableLanguages() const;
76 
77 private:
78 	typedef std::map<std::string, std::string> StrStrMap;
79 
80 	int         ReadSingleTranslation (const char* pszCurrent, ...);
81 	std::string ReadSingleTranslation (const std::string& strInput);
82 	int         ReadLanguagePackFooter();
83 	int         ReadLanguagePackFooter (const std::string& strLanguageCode);
84 	int         ReadLanguageMaster();
85 	int         ReadRecursiveLanguagePack (tinyxml2::XMLElement* xmlElement, std::string strNodePath);
86 
87 	int         checkTimeStamp (std::string rstrData);
88 
89 	tinyxml2::XMLDocument m_XmlDoc;
90 	// Use ISO 639-2 codes to identify languages
91 	// (http://www.loc.gov/standards/iso639-2/php/code_list.php)
92 	std::string m_szLanguage;
93 	std::string m_szLanguageFile;
94 	std::string m_szLanguageFileMaster;
95 	std::string m_szEncoding;
96 	std::string m_szLastEditor;
97 	StrStrMap   m_mpLanguage;
98 	bool        m_bLeftToRight;
99 	bool        m_bErrorMsgTranslationLoaded;
100 };
101 
102 #endif // utility_languageH
103