diff options
Diffstat (limited to 'src/mgr/localemgr.cpp')
-rw-r--r-- | src/mgr/localemgr.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/mgr/localemgr.cpp b/src/mgr/localemgr.cpp index ead076a..af57ca0 100644 --- a/src/mgr/localemgr.cpp +++ b/src/mgr/localemgr.cpp @@ -2,7 +2,7 @@ * localemgr.cpp - implementation of class LocaleMgr used to interact with * registered locales for a sword installation * - * $Id: localemgr.cpp 2080 2007-09-17 06:21:29Z scribe $ + * $Id: localemgr.cpp 2321 2009-04-13 01:17:00Z scribe $ * * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -49,8 +49,9 @@ public: LocaleMgr *LocaleMgr::getSystemLocaleMgr() { - if (!systemLocaleMgr) - systemLocaleMgr = new LocaleMgr(); + if (!systemLocaleMgr) { + setSystemLocaleMgr(new LocaleMgr()); + } return systemLocaleMgr; } @@ -60,6 +61,8 @@ void LocaleMgr::setSystemLocaleMgr(LocaleMgr *newLocaleMgr) { if (systemLocaleMgr) delete systemLocaleMgr; systemLocaleMgr = newLocaleMgr; + SWLocale *locale = new SWLocale(0); + systemLocaleMgr->locales->insert(LocaleMap::value_type(locale->getName(), locale)); } @@ -67,18 +70,29 @@ LocaleMgr::LocaleMgr(const char *iConfigPath) { locales = new LocaleMap(); char *prefixPath = 0; char *configPath = 0; + SWConfig *sysConf = 0; char configType = 0; SWBuf path; std::list<SWBuf> augPaths; + ConfigEntMap::iterator entry; defaultLocaleName = 0; if (!iConfigPath) { SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY..."); - SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths); + SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConf); + if (sysConf) { + if ((entry = sysConf->Sections["Install"].find("LocalePath")) != sysConf->Sections["Install"].end()) { + configType = 9; // our own + stdstr(&prefixPath, (char *)entry->second.c_str()); + SWLog::getSystemLog()->logDebug("LocalePath provided in sysConfig."); + } + } SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY COMPLETE."); } - else configPath = (char *)iConfigPath; + else { + loadConfigDir(iConfigPath); + } if (prefixPath) { switch (configType) { @@ -102,7 +116,7 @@ LocaleMgr::LocaleMgr(const char *iConfigPath) { } } - if (augPaths.size()) { //load locale files from all augmented paths + if (augPaths.size() && configType != 9) { //load locale files from all augmented paths std::list<SWBuf>::iterator it = augPaths.begin(); std::list<SWBuf>::iterator end = augPaths.end(); @@ -117,13 +131,16 @@ LocaleMgr::LocaleMgr(const char *iConfigPath) { // Locales will be invalidated if you change the StringMgr // So only use the default hardcoded locale and let the // frontends change the locale if they want - stdstr(&defaultLocaleName, "en_US"); + stdstr(&defaultLocaleName, SWLocale::DEFAULT_LOCALE_NAME); if (prefixPath) delete [] prefixPath; if (configPath) delete [] configPath; + + if (sysConf) + delete sysConf; } @@ -200,7 +217,7 @@ SWLocale *LocaleMgr::getLocale(const char *name) { return (*it).second; SWLog::getSystemLog()->logWarning("LocaleMgr::getLocale failed to find %s\n", name); - return 0; + return (*locales)[SWLocale::DEFAULT_LOCALE_NAME]; } |