Rev 104 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "Languages.h"#include <stdarg.h>CLanguages *CLanguages::_pInstance = NULL;void CLanguages::DEBUG_AddDefaultTexts(){if (_lTexts){_pDefaultLang = &(*_lTexts)[44];{LangPage &page = (*_pDefaultLang)[LS_STARTUP];page[LANGSTARTUP_ANOTHERINSTANCE_TITLE] = "Another Instance Detected";page[LANGSTARTUP_ANOTHERINSTANCE] = "Another instance of the plugin manager is already running";page[LANGSTARTUP_LOCKEDDIR_TITLE] = "Directory Locked";page[LANGSTARTUP_LOCKEDDIR] = "ERROR: The game directory:\n%s\n\nIs locked and unable to add/remove any plugins";page[LANGSTARTUP_PROTECTEDDIR] = "";}{LangPage &page = (*_pDefaultLang)[LS_DIRECTORY];page[LANGDIR_TITLE] = "Directory Control";}}}CLanguages::CLanguages() :_iLanguage(-1),_pDefaultLang(NULL),_pCurrentLang(NULL){_lTexts = new LangTexts();}CLanguages::~CLanguages(){delete _lTexts;_pDefaultLang = NULL;_pCurrentLang = NULL;}CLanguages *CLanguages::Instance(){if ( !_pInstance ) {_pInstance = new CLanguages();_pInstance->DEBUG_AddDefaultTexts();}return _pInstance;}void CLanguages::Release(){if ( _pInstance ) {delete _pInstance;_pInstance = NULL;}}void CLanguages::SetLanguage(int lang){_iLanguage = lang;_pCurrentLang = NULL;if (_lTexts){auto itr = _lTexts->find(lang);if (itr != _lTexts->end())_pCurrentLang = &itr->second;}}Utils::String CLanguages::findText(int section, int id){LangPages *text = _pCurrentLang;if (!text) text = _pDefaultLang;if (!text) text = _findLanguageText();Utils::String out;if (_findText(text, section, id, &out))return out;if (_pDefaultLang && text != _pDefaultLang){if (_findText(_pDefaultLang, section, id, &out))return out;}return _error(section, id);}bool CLanguages::_findText(LangPages *texts, int section, int id, Utils::String *out) const{if (texts){auto itr = texts->find(section);if (itr != texts->end()){LangPage *m = &itr->second;auto itr2 = m->find(id);if (itr2 != m->end()){if (out)(*out) = itr2->second;return true;}}}return false;}LangPages *CLanguages::_findLanguageText(int id) const{if ( id == -1 ) id = _iLanguage;if ( _lTexts ) {auto itr = _lTexts->find(id);if (itr != _lTexts->end())return &itr->second;}return NULL;}Utils::String CLanguages::_error(int section, int id) const{return "ReadText" + Utils::String::Number(section) + "-" + Utils::String::Number(id);}