lang.h
Header for language support.
Classes:
Public Defines
define
LANG_INVALID_ID() 0xffffffff
Public Functions
UTF8 *
getCurrentModVarName(UTF8 * buffer, U32 bufsize)
getModLangTable(const UTF8 * mod)
Detailed Description
Header for language support.
Public Defines
LANG_INVALID_ID() 0xffffffff
Public Functions
getCurrentModLangTable()
getCurrentModVarName(UTF8 * buffer, U32 bufsize)
getModLangTable(const UTF8 * mod)
sanitiseVarName(const UTF8 * varName, UTF8 * buffer, U32 bufsize)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24//----------------------------------------------------------------------------- 25/// \file lang.h 26/// \brief Header for language support 27//----------------------------------------------------------------------------- 28 29#include "console/simBase.h" 30#include "core/util/tVector.h" 31//lang_ localization 32#include "core/fileObject.h" 33#include "core/util/str.h" 34#include "core/strings/unicode.h" 35 36#ifndef _LANG_H_ 37#define _LANG_H_ 38 39#define LANG_INVALID_ID 0xffffffff ///!< Invalid ID. Used for returning failure 40 41//----------------------------------------------------------------------------- 42/// \brief Class for working with language files 43//----------------------------------------------------------------------------- 44class LangFile 45{ 46protected: 47 Vector<UTF8*> mStringTable; 48 UTF8 * mLangName; 49 UTF8 * mLangFile; 50 51 void freeTable(); 52 53public: 54 LangFile(const UTF8 *langName = NULL); 55 virtual ~LangFile(); 56 57 bool load(const UTF8 *filename); 58 bool save(const UTF8 *filename); 59 60 bool load(Stream *s); 61 bool save(Stream *s); 62 63 const UTF8 * getString(U32 id); 64 U32 addString(const UTF8 *str); 65 66 // [tom, 4/22/2005] setString() added to help the language compiler a bit 67 void setString(U32 id, const UTF8 *str); 68 69 void setLangName(const UTF8 *newName); 70 const UTF8 *getLangName(void) { return mLangName; } 71 const UTF8 *getLangFile(void) { return mLangFile; } 72 73 void setLangFile(const UTF8 *langFile); 74 bool activateLanguage(void); 75 void deactivateLanguage(void); 76 77 bool isLoaded(void) { return mStringTable.size() > 0; } 78 79 S32 getNumStrings(void) { return mStringTable.size(); } 80}; 81 82//----------------------------------------------------------------------------- 83/// \brief Language file table 84//----------------------------------------------------------------------------- 85class LangTable : public SimObject 86{ 87 typedef SimObject Parent; 88 89protected: 90 Vector<LangFile*> mLangTable; 91 S32 mDefaultLang; 92 S32 mCurrentLang; 93 94public: 95 DECLARE_CONOBJECT(LangTable); 96 97 LangTable(); 98 virtual ~LangTable(); 99 100 S32 addLanguage(LangFile *lang, const UTF8 *name = NULL); 101 S32 addLanguage(const UTF8 *filename, const UTF8 *name = NULL); 102 103 void setDefaultLanguage(S32 langid); 104 void setCurrentLanguage(S32 langid); 105 S32 getCurrentLanguage(void) { return mCurrentLang; } 106 107 const UTF8 * getLangName(const S32 langid) const 108 { 109 if(langid < 0 || langid >= mLangTable.size()) 110 return NULL; 111 return mLangTable[langid]->getLangName(); 112 } 113 114 const S32 getNumLang(void) const { return mLangTable.size(); } 115 116 const UTF8 * getString(const U32 id) const; 117 const U32 getStringLength(const U32 id) const; 118}; 119 120extern UTF8 *sanitiseVarName(const UTF8 *varName, UTF8 *buffer, U32 bufsize); 121extern UTF8 *getCurrentModVarName(UTF8 *buffer, U32 bufsize); 122extern const LangTable *getCurrentModLangTable(); 123extern const LangTable *getModLangTable(const UTF8 *mod); 124 125#endif // _LANG_H_ 126