@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
# include "HeadSpin.h"
# include "HeadSpin.h"
# include "plString.h"
# include "plResMgr/plLocalization.h"
# include "plResMgr/plLocalization.h"
@ -59,7 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
# include "pfLocalizationDataMgr.h"
# include "pfLocalizationDataMgr.h"
# include <expat.h>
# include <expat.h>
# include <stack>
# include <stack>
// MinGW sucks
// MinGW sucks
@ -97,7 +97,7 @@ public:
typedef std : : map < std : : wstring , age > ageMap ;
typedef std : : map < std : : wstring , age > ageMap ;
protected :
protected :
std : : wstring fLastError ;
bool fWeExploded ; // alternative to massive error stack
std : : string fFilename ;
std : : string fFilename ;
XML_Parser fParser ;
XML_Parser fParser ;
@ -124,12 +124,10 @@ protected:
void IHandleTranslationTag ( const tagInfo & parentTag , const tagInfo & thisTag ) ;
void IHandleTranslationTag ( const tagInfo & parentTag , const tagInfo & thisTag ) ;
public :
public :
LocalizationXMLFile ( ) : fLastError ( L " " ) , fFilename ( " " ) { }
LocalizationXMLFile ( ) : fWeExploded ( false ) , fFilename ( " " ) { }
bool Parse ( const std : : string & fileName ) ; // returns false on failure
bool Parse ( const std : : string & fileName ) ; // returns false on failure
void AddError ( const std : : wstring & errorText ) ;
void AddError ( const plString & errorText ) ;
std : : wstring GetLastError ( ) { return fLastError ; }
} ;
} ;
// A few small helper structs
// A few small helper structs
@ -211,7 +209,7 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme
else if ( wElement = = L " translation " )
else if ( wElement = = L " translation " )
file - > IHandleTranslationTag ( parentTag , newTag ) ;
file - > IHandleTranslationTag ( parentTag , newTag ) ;
else
else
file - > AddError ( L " Unknown tag " + wElement + L " found " ) ;
file - > AddError ( plString : : Format ( " Unknown tag %S found " , wElement . c_str ( ) ) ) ;
}
}
//metmet remove static and include the function inside LocalizationXMLFile
//metmet remove static and include the function inside LocalizationXMLFile
void XMLCALL LocalizationXMLFile : : EndTag ( void * userData , const XML_Char * element )
void XMLCALL LocalizationXMLFile : : EndTag ( void * userData , const XML_Char * element )
@ -251,10 +249,7 @@ void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *dat
// This gets all data between tags, including indentation and newlines
// This gets all data between tags, including indentation and newlines
// so we'll have to ignore data when we aren't expecting it (not in a translation tag)
// so we'll have to ignore data when we aren't expecting it (not in a translation tag)
std : : wstring wData = L " " ;
std : : wstring wData = std : : wstring ( data , stringLength ) ;
for ( int i = 0 ; i < stringLength ; i + + )
wData + = data [ i ] ;
// we must be in a translation tag since that's the only tag that doesn't ignore the contents
// we must be in a translation tag since that's the only tag that doesn't ignore the contents
file - > fData [ file - > fCurrentAge ] [ file - > fCurrentSet ] [ file - > fCurrentElement ] [ file - > fCurrentTranslation ] + = wData ;
file - > fData [ file - > fCurrentAge ] [ file - > fCurrentSet ] [ file - > fCurrentElement ] [ file - > fCurrentTranslation ] + = wData ;
@ -272,7 +267,7 @@ void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tag
{
{
if ( parentTag . fTag ! = L " " ) // we only allow <localizations> tags at root level
if ( parentTag . fTag ! = L " " ) // we only allow <localizations> tags at root level
{
{
AddError ( L " localizations tag only allowed at root level " ) ;
AddError ( " localizations tag only allowed at root level " ) ;
return ;
return ;
}
}
}
}
@ -284,14 +279,14 @@ void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & par
// it has to be inside the subtitles tag
// it has to be inside the subtitles tag
if ( parentTag . fTag ! = L " localizations " )
if ( parentTag . fTag ! = L " localizations " )
{
{
AddError ( L " age tag can only be directly inside a localizations tag " ) ;
AddError ( " age tag can only be directly inside a localizations tag " ) ;
return ;
return ;
}
}
// we have to have a name attribute
// we have to have a name attribute
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
{
{
AddError ( L " age tag is missing the name attribute " ) ;
AddError ( " age tag is missing the name attribute " ) ;
return ;
return ;
}
}
@ -305,14 +300,14 @@ void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & par
// it has to be inside the age tag
// it has to be inside the age tag
if ( parentTag . fTag ! = L " age " )
if ( parentTag . fTag ! = L " age " )
{
{
AddError ( L " set tag can only be directly inside a age tag " ) ;
AddError ( " set tag can only be directly inside a age tag " ) ;
return ;
return ;
}
}
// we have to have a name attribute
// we have to have a name attribute
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
{
{
AddError ( L " set tag is missing the name attribute " ) ;
AddError ( " set tag is missing the name attribute " ) ;
return ;
return ;
}
}
@ -326,14 +321,14 @@ void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo &
// it has to be inside the element tag
// it has to be inside the element tag
if ( parentTag . fTag ! = L " set " )
if ( parentTag . fTag ! = L " set " )
{
{
AddError ( L " element tag can only be directly inside a set tag " ) ;
AddError ( " element tag can only be directly inside a set tag " ) ;
return ;
return ;
}
}
// we have to have a name attribute
// we have to have a name attribute
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
if ( thisTag . fAttributes . find ( L " name " ) = = thisTag . fAttributes . end ( ) )
{
{
AddError ( L " element tag is missing the name attribute " ) ;
AddError ( " element tag is missing the name attribute " ) ;
return ;
return ;
}
}
@ -347,14 +342,14 @@ void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagIn
// it has to be inside the element tag
// it has to be inside the element tag
if ( parentTag . fTag ! = L " element " )
if ( parentTag . fTag ! = L " element " )
{
{
AddError ( L " translation tag can only be directly inside a element tag " ) ;
AddError ( " translation tag can only be directly inside a element tag " ) ;
return ;
return ;
}
}
// we have to have a language attribute
// we have to have a language attribute
if ( thisTag . fAttributes . find ( L " language " ) = = thisTag . fAttributes . end ( ) )
if ( thisTag . fAttributes . find ( L " language " ) = = thisTag . fAttributes . end ( ) )
{
{
AddError ( L " translation tag is missing the language attribute " ) ;
AddError ( " translation tag is missing the language attribute " ) ;
return ;
return ;
}
}
@ -368,8 +363,6 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
{
{
fFilename = fileName ;
fFilename = fileName ;
fLastError = L " " ;
while ( ! fTagStack . empty ( ) )
while ( ! fTagStack . empty ( ) )
fTagStack . pop ( ) ;
fTagStack . pop ( ) ;
@ -386,7 +379,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
fParser = XML_ParserCreate_MM ( NULL , & gHeapAllocator , NULL ) ;
fParser = XML_ParserCreate_MM ( NULL , & gHeapAllocator , NULL ) ;
if ( ! fParser )
if ( ! fParser )
{
{
fLastError = L " ERROR: Couldn't allocate memory for parser " ;
AddError ( " ERROR: Couldn't allocate memory for parser " ) ;
return false ;
return false ;
}
}
@ -397,17 +390,13 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
hsStream * xmlStream = plEncryptedStream : : OpenEncryptedFile ( fileName . c_str ( ) ) ;
hsStream * xmlStream = plEncryptedStream : : OpenEncryptedFile ( fileName . c_str ( ) ) ;
if ( ! xmlStream )
if ( ! xmlStream )
{
{
wchar_t * wFilename = hsStringToWString ( fileName . c_str ( ) ) ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " ERROR: Can't open file stream for %s " , fileName . c_str ( ) ) ;
fLastError + = L " ERROR: Can't open file stream for " ;
fLastError + = wFilename ;
fLastError + = L " \n " ;
delete [ ] wFilename ;
return false ;
return false ;
}
}
for ( ; ; )
bool done = false ;
do
{
{
int done ;
size_t len ;
size_t len ;
len = xmlStream - > Read ( FILEBUFFERSIZE , Buff ) ;
len = xmlStream - > Read ( FILEBUFFERSIZE , Buff ) ;
@ -415,32 +404,15 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
if ( XML_Parse ( fParser , Buff , ( int ) len , done ) = = XML_STATUS_ERROR )
if ( XML_Parse ( fParser , Buff , ( int ) len , done ) = = XML_STATUS_ERROR )
{
{
wchar_t lineNumber [ 256 ] ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " ERROR: Parse error at line %d: %S " ,
swprintf ( lineNumber , 256 , L " %d " , XML_GetCurrentLineNumber ( fParser ) ) ;
XML_GetCurrentLineNumber ( fParser ) , XML_ErrorString ( XML_GetErrorCode ( fParser ) ) ) ;
fLastError + = L " ERROR: Parse error at line " ;
done = true ;
fLastError + = lineNumber ;
fLastError + = L " : " ;
fLastError + = XML_ErrorString ( XML_GetErrorCode ( fParser ) ) ;
fLastError + = L " \n " ;
XML_ParserFree ( fParser ) ;
fParser = nil ;
xmlStream - > Close ( ) ;
delete xmlStream ;
return false ;
}
}
if ( fLastError ! = L " " ) // some error occurred in the parser
if ( fWeExploded ) // some error occurred in the parser
{
done = true ;
XML_ParserFree ( fParser ) ;
} while ( ! done ) ;
fParser = nil ;
xmlStream - > Close ( ) ;
delete xmlStream ;
return false ;
}
if ( done )
break ;
}
XML_ParserFree ( fParser ) ;
XML_ParserFree ( fParser ) ;
fParser = nil ;
fParser = nil ;
xmlStream - > Close ( ) ;
xmlStream - > Close ( ) ;
@ -450,14 +422,12 @@ bool LocalizationXMLFile::Parse(const std::string & fileName)
//// AddError() //////////////////////////////////////////////////////
//// AddError() //////////////////////////////////////////////////////
void LocalizationXMLFile : : AddError ( const std : : wstring & errorText )
void LocalizationXMLFile : : AddError ( const plString & errorText )
{
{
wchar_t lineNumber [ 256 ] ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " ERROR (line %d): %s " ,
swprintf ( lineNumber , 256 , L " %d " , XML_GetCurrentLineNumber ( fParser ) ) ;
XML_GetCurrentLineNumber ( fParser ) , errorText . c_str ( ) ) ;
fLastError + = L " ERROR (line " ;
fLastError + = lineNumber ;
fLastError + = L " ): " + errorText + L " \n " ;
fSkipDepth = fTagStack . size ( ) ; // skip this block
fSkipDepth = fTagStack . size ( ) ; // skip this block
fWeExploded = true ;
return ;
return ;
}
}
@ -473,7 +443,6 @@ class LocalizationDatabase
{
{
protected :
protected :
std : : string fDirectory ; // the directory we're supposed to parse
std : : string fDirectory ; // the directory we're supposed to parse
std : : wstring fErrorString ; // total sum of all errors encountered (also has warnings and status messages)
std : : vector < LocalizationXMLFile > fFiles ; // the various XML files in that directory
std : : vector < LocalizationXMLFile > fFiles ; // the various XML files in that directory
@ -493,8 +462,6 @@ public:
LocalizationDatabase ( ) { }
LocalizationDatabase ( ) { }
void Parse ( const std : : string & directory ) ;
void Parse ( const std : : string & directory ) ;
void ResetOutput ( ) { fErrorString = L " " ; }
std : : wstring GetOutput ( ) { return fErrorString ; }
LocalizationXMLFile : : ageMap GetData ( ) { return fData ; }
LocalizationXMLFile : : ageMap GetData ( ) { return fData ; }
} ;
} ;
@ -512,7 +479,10 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio
for ( curTranslation = secondElement . begin ( ) ; curTranslation ! = secondElement . end ( ) ; curTranslation + + )
for ( curTranslation = secondElement . begin ( ) ; curTranslation ! = secondElement . end ( ) ; curTranslation + + )
{
{
if ( firstElement . find ( curTranslation - > first ) ! = firstElement . end ( ) )
if ( firstElement . find ( curTranslation - > first ) ! = firstElement . end ( ) )
fErrorString + = L " Duplicate " + curTranslation - > first + L " translation for " + path + L " found in file " + fileName + L " Ignoring second translation \n " ;
{
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " Duplicate %S translation for %S found in file %S Ignoring second translation " ,
curTranslation - > first . c_str ( ) , path . c_str ( ) , fileName . c_str ( ) ) ;
}
else
else
firstElement [ curTranslation - > first ] = curTranslation - > second ;
firstElement [ curTranslation - > first ] = curTranslation - > second ;
}
}
@ -584,7 +554,7 @@ void LocalizationDatabase::IMergeData()
void LocalizationDatabase : : IVerifyElement ( const std : : wstring & ageName , const std : : wstring & setName , LocalizationXMLFile : : set : : iterator & curElement )
void LocalizationDatabase : : IVerifyElement ( const std : : wstring & ageName , const std : : wstring & setName , LocalizationXMLFile : : set : : iterator & curElement )
{
{
std : : vector < std : : wstring > languageNames ;
WStringVector languageNames ;
std : : wstring defaultLanguage ;
std : : wstring defaultLanguage ;
int numLocales = plLocalization : : GetNumLocales ( ) ;
int numLocales = plLocalization : : GetNumLocales ( ) ;
@ -616,8 +586,8 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std
if ( ! languageExists )
if ( ! languageExists )
{
{
fErrorString + = L " ERROR: The language " + curTranslation - > first + L " used by " + ageName + L " . " + setName + L " . " ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " ERROR: The language %S used by %S.%S.%S is not supported, discarding translation " ,
fErrorString + = elementName + L " is not supported, discarding translation \n " ;
curTranslation - > first . c_str ( ) , ageName . c_str ( ) , setName . c_str ( ) , elementName . c_str ( ) ) ;
curTranslation = theElement . erase ( curTranslation ) ;
curTranslation = theElement . erase ( curTranslation ) ;
}
}
else
else
@ -628,8 +598,8 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std
{
{
if ( theElement . find ( languageNames [ i ] ) = = theElement . end ( ) )
if ( theElement . find ( languageNames [ i ] ) = = theElement . end ( ) )
{
{
fErrorString + = L " WARNING: Language " + languageNames [ i ] + L " is missing from the translations in element " ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " WARNING: Language %S is missing from the translations in element %S.%S.%S, you'll want to get translations for that! " ,
fErrorString + = ageName + L " . " + setName + L " . " + elementName + L " , you'll want to get translations for that! \n " ;
languageNames [ i ] . c_str ( ) , ageName . c_str ( ) , setName . c_str ( ) , elementName . c_str ( ) ) ;
}
}
}
}
}
}
@ -649,8 +619,8 @@ void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::ws
// Check that we at least have a default language translation for fallback
// Check that we at least have a default language translation for fallback
if ( curElement - > second . find ( defaultLanguage ) = = curElement - > second . end ( ) )
if ( curElement - > second . find ( defaultLanguage ) = = curElement - > second . end ( ) )
{
{
fErrorString + = L " ERROR: Default language " + defaultLanguage + L " is missing from the translations in element " ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " ERROR: Default language %S is missing from the translations in element %S.%S.%S, deleting element " ,
fErrorString + = ageName + L " . " + setName + L " . " + curElement - > first + L " , deleting element \n " ;
defaultLanguage . c_str ( ) , ageName . c_str ( ) , setName . c_str ( ) , curElement - > first . c_str ( ) ) ;
curElement = theSet . erase ( curElement ) ;
curElement = theSet . erase ( curElement ) ;
}
}
else
else
@ -686,7 +656,6 @@ void LocalizationDatabase::Parse(const std::string & directory)
{
{
fDirectory = directory ;
fDirectory = directory ;
fFiles . clear ( ) ;
fFiles . clear ( ) ;
fErrorString = L " " ;
char filename [ 255 ] ;
char filename [ 255 ] ;
hsFolderIterator xmlFolder ( ( directory + PATH_SEPARATOR_STR ) . c_str ( ) ) ;
hsFolderIterator xmlFolder ( ( directory + PATH_SEPARATOR_STR ) . c_str ( ) ) ;
@ -694,18 +663,13 @@ void LocalizationDatabase::Parse(const std::string & directory)
{
{
xmlFolder . GetPathAndName ( filename ) ;
xmlFolder . GetPathAndName ( filename ) ;
wchar_t * buff = hsStringToWString ( filename ) ;
std : : wstring wFilename = buff ;
delete [ ] buff ;
LocalizationXMLFile newFile ;
LocalizationXMLFile newFile ;
bool retVal = newFile . Parse ( filename ) ;
bool retVal = newFile . Parse ( filename ) ;
if ( ! retVal )
if ( ! retVal )
fErrorString + = L " Errors in file " + wFilename + L " : \n " + newFile . GetLastError ( ) + L " \n " ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " WARNING: Errors in file %s " , filename ) ;
fFiles . push_back ( newFile ) ;
fFiles . push_back ( newFile ) ;
pfLocalizationDataMgr : : GetLog ( ) - > AddLineF ( " File %s parsed and added to database " , filename ) ;
fErrorString + = L " File " + wFilename + L " parsed and added to database \n " ;
}
}
IMergeData ( ) ;
IMergeData ( ) ;
@ -818,9 +782,9 @@ mapT &pfLocalizationDataMgr::pf3PartMap<mapT>::operator[](const std::wstring &ke
//// getAgeList() ////////////////////////////////////////////////////
//// getAgeList() ////////////////////////////////////////////////////
template < class mapT >
template < class mapT >
std : : vector < std : : wstring > pfLocalizationDataMgr : : pf3PartMap < mapT > : : getAgeList ( )
WStringVector pfLocalizationDataMgr : : pf3PartMap < mapT > : : getAgeList ( )
{
{
std : : vector < std : : wstring > retVal ;
WStringVector retVal ;
typename ThreePartMap : : iterator curAge ;
typename ThreePartMap : : iterator curAge ;
for ( curAge = fData . begin ( ) ; curAge ! = fData . end ( ) ; curAge + + )
for ( curAge = fData . begin ( ) ; curAge ! = fData . end ( ) ; curAge + + )
@ -832,9 +796,9 @@ std::vector<std::wstring> pfLocalizationDataMgr::pf3PartMap<mapT>::getAgeList()
//// getSetList() ////////////////////////////////////////////////////
//// getSetList() ////////////////////////////////////////////////////
template < class mapT >
template < class mapT >
std : : vector < std : : wstring > pfLocalizationDataMgr : : pf3PartMap < mapT > : : getSetList ( const std : : wstring & age )
WStringVector pfLocalizationDataMgr : : pf3PartMap < mapT > : : getSetList ( const std : : wstring & age )
{
{
std : : vector < std : : wstring > retVal ;
WStringVector retVal ;
typename std : : map < std : : wstring , std : : map < std : : wstring , mapT > > : : iterator curSet ;
typename std : : map < std : : wstring , std : : map < std : : wstring , mapT > > : : iterator curSet ;
if ( fData . find ( age ) = = fData . end ( ) )
if ( fData . find ( age ) = = fData . end ( ) )
@ -849,9 +813,9 @@ std::vector<std::wstring> pfLocalizationDataMgr::pf3PartMap<mapT>::getSetList(co
//// getNameList() ///////////////////////////////////////////////////
//// getNameList() ///////////////////////////////////////////////////
template < class mapT >
template < class mapT >
std : : vector < std : : wstring > pfLocalizationDataMgr : : pf3PartMap < mapT > : : getNameList ( const std : : wstring & age , const std : : wstring & set )
WStringVector pfLocalizationDataMgr : : pf3PartMap < mapT > : : getNameList ( const std : : wstring & age , const std : : wstring & set )
{
{
std : : vector < std : : wstring > retVal ;
WStringVector retVal ;
typename std : : map < std : : wstring , mapT > : : iterator curName ;
typename std : : map < std : : wstring , mapT > : : iterator curName ;
if ( fData . find ( age ) = = fData . end ( ) )
if ( fData . find ( age ) = = fData . end ( ) )
@ -928,10 +892,10 @@ std::wstring pfLocalizationDataMgr::IGetCurrentLanguageName()
//// IGetAllLanguageNames ////////////////////////////////////////////
//// IGetAllLanguageNames ////////////////////////////////////////////
std : : vector < std : : wstring > pfLocalizationDataMgr : : IGetAllLanguageNames ( )
WStringVector pfLocalizationDataMgr : : IGetAllLanguageNames ( )
{
{
int numLocales = plLocalization : : GetNumLocales ( ) ;
int numLocales = plLocalization : : GetNumLocales ( ) ;
std : : vector < std : : wstring > retVal ;
WStringVector retVal ;
for ( int curLocale = 0 ; curLocale < = numLocales ; curLocale + + )
for ( int curLocale = 0 ; curLocale < = numLocales ; curLocale + + )
{
{
@ -959,12 +923,7 @@ void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const s
if ( numArgs = = - 1 ) // just started
if ( numArgs = = - 1 ) // just started
numArgs = argCount ;
numArgs = argCount ;
else if ( argCount ! = numArgs )
else if ( argCount ! = numArgs )
{
fLog - > AddLineF ( " WARNING: Argument number mismatch in element %S for %S " , curPath . c_str ( ) , curTranslation - > first . c_str ( ) ) ;
std : : wstring errorStr = L " WARNING: Argument number mismatch in element " + curPath + L " for " + curTranslation - > first ;
char * cErrorStr = hsWStringToString ( errorStr . c_str ( ) ) ;
fLog - > AddLine ( cErrorStr ) ;
delete [ ] cErrorStr ;
}
}
}
fLocalizedElements [ curPath ] = newElement ;
fLocalizedElements [ curPath ] = newElement ;
@ -1035,14 +994,14 @@ void pfLocalizationDataMgr::IWriteText(const std::string & filename, const std::
fileData + = L " <localizations> \n " ;
fileData + = L " <localizations> \n " ;
fileData + = L " \t <age name= \" " + ageName + L " \" > \n " ;
fileData + = L " \t <age name= \" " + ageName + L " \" > \n " ;
std : : vector < std : : wstring > setNames = GetSetList ( ageName ) ;
WStringVector setNames = GetSetList ( ageName ) ;
for ( int curSet = 0 ; curSet < setNames . size ( ) ; curSet + + )
for ( int curSet = 0 ; curSet < setNames . size ( ) ; curSet + + )
{
{
setEmpty = true ; // so far, this set is empty
setEmpty = true ; // so far, this set is empty
std : : wstring setCode = L " " ;
std : : wstring setCode = L " " ;
setCode + = L " \t \t <set name= \" " + setNames [ curSet ] + L " \" > \n " ;
setCode + = L " \t \t <set name= \" " + setNames [ curSet ] + L " \" > \n " ;
std : : vector < std : : wstring > elementNames = GetElementList ( ageName , setNames [ curSet ] ) ;
WStringVector elementNames = GetElementList ( ageName , setNames [ curSet ] ) ;
for ( int curElement = 0 ; curElement < elementNames . size ( ) ; curElement + + )
for ( int curElement = 0 ; curElement < elementNames . size ( ) ; curElement + + )
{
{
setCode + = L " \t \t \t <element name= \" " + elementNames [ curElement ] + L " \" > \n " ;
setCode + = L " \t \t \t <element name= \" " + elementNames [ curElement ] + L " \" > \n " ;
@ -1123,10 +1082,6 @@ void pfLocalizationDataMgr::SetupData()
fDatabase = new LocalizationDatabase ( ) ;
fDatabase = new LocalizationDatabase ( ) ;
fDatabase - > Parse ( fDataPath ) ;
fDatabase - > Parse ( fDataPath ) ;
char * temp = hsWStringToString ( fDatabase - > GetOutput ( ) . c_str ( ) ) ;
fLog - > AddLine ( temp ) ;
delete [ ] temp ;
fLog - > AddLine ( " File reading complete, converting to native data format " ) ;
fLog - > AddLine ( " File reading complete, converting to native data format " ) ;
// and now we read all the data out of the database and convert it to our native formats
// and now we read all the data out of the database and convert it to our native formats
@ -1181,32 +1136,11 @@ pfLocalizedString pfLocalizationDataMgr::GetSpecificElement(const std::wstring &
return retVal ;
return retVal ;
}
}
//// GetAgeList //////////////////////////////////////////////////////
std : : vector < std : : wstring > pfLocalizationDataMgr : : GetAgeList ( )
{
return fLocalizedElements . getAgeList ( ) ;
}
//// GetSetList //////////////////////////////////////////////////////
std : : vector < std : : wstring > pfLocalizationDataMgr : : GetSetList ( const std : : wstring & ageName )
{
return fLocalizedElements . getSetList ( ageName ) ;
}
//// GetElementList //////////////////////////////////////////////////
std : : vector < std : : wstring > pfLocalizationDataMgr : : GetElementList ( const std : : wstring & ageName , const std : : wstring & setName )
{
return fLocalizedElements . getNameList ( ageName , setName ) ;
}
//// GetLanguages ////////////////////////////////////////////////////
//// GetLanguages ////////////////////////////////////////////////////
std : : vector < std : : wstring > pfLocalizationDataMgr : : GetLanguages ( const std : : wstring & ageName , const std : : wstring & setName , const std : : wstring & elementName )
WStringVector pfLocalizationDataMgr : : GetLanguages ( const std : : wstring & ageName , const std : : wstring & setName , const std : : wstring & elementName )
{
{
std : : vector < std : : wstring > retVal ;
WStringVector retVal ;
std : : wstring key = ageName + L " . " + setName + L " . " + elementName ;
std : : wstring key = ageName + L " . " + setName + L " . " + elementName ;
if ( fLocalizedElements . exists ( key ) )
if ( fLocalizedElements . exists ( key ) )
{
{
@ -1216,7 +1150,7 @@ std::vector<std::wstring> pfLocalizationDataMgr::GetLanguages(const std::wstring
for ( curLanguage = elem . begin ( ) ; curLanguage ! = elem . end ( ) ; curLanguage + + )
for ( curLanguage = elem . begin ( ) ; curLanguage ! = elem . end ( ) ; curLanguage + + )
{
{
std : : wstring language = curLanguage - > first ;
std : : wstring language = curLanguage - > first ;
if ( language ! = L " " ) // somehow blank language names sneak in... so don't return them
if ( ! language . empty ( ) ) // somehow blank language names sneak in... so don't return them
retVal . push_back ( curLanguage - > first ) ;
retVal . push_back ( curLanguage - > first ) ;
}
}
}
}
@ -1326,8 +1260,8 @@ bool pfLocalizationDataMgr::DeleteElement(const std::wstring & name)
void pfLocalizationDataMgr : : WriteDatabaseToDisk ( const std : : string & path )
void pfLocalizationDataMgr : : WriteDatabaseToDisk ( const std : : string & path )
{
{
// first, write the styles and panel settings to styles.sub
// first, write the styles and panel settings to styles.sub
std : : vector < std : : wstring > ageNames = GetAgeList ( ) ;
WStringVector ageNames = GetAgeList ( ) ;
std : : vector < std : : wstring > languageNames = IGetAllLanguageNames ( ) ;
WStringVector languageNames = IGetAllLanguageNames ( ) ;
for ( int curAge = 0 ; curAge < ageNames . size ( ) ; curAge + + )
for ( int curAge = 0 ; curAge < ageNames . size ( ) ; curAge + + )
{
{
for ( int curLanguage = 0 ; curLanguage < languageNames . size ( ) ; curLanguage + + )
for ( int curLanguage = 0 ; curLanguage < languageNames . size ( ) ; curLanguage + + )
@ -1349,41 +1283,27 @@ void pfLocalizationDataMgr::WriteDatabaseToDisk(const std::string & path)
void pfLocalizationDataMgr : : OutputTreeToLog ( )
void pfLocalizationDataMgr : : OutputTreeToLog ( )
{
{
std : : vector < std : : wstring > ages = GetAgeList ( ) ;
WStringVector ages = GetAgeList ( ) ;
fLog - > AddLine ( " \n " ) ;
fLog - > AddLine ( " \n " ) ;
fLog - > AddLine ( " Localization tree: \n " ) ;
fLog - > AddLine ( " Localization tree: \n " ) ;
for ( int i = 0 ; i < ages . siz e( ) ; i + + )
for ( WStringVector : : iterator i = ages . begin ( ) ; i ! = ages . end ( ) ; + + i )
{
{
char * ageName = hsWStringToString ( ages [ i ] . c_str ( ) ) ;
std : : wstring age = * i ;
std : : string temp = ageName ;
fLog - > AddLineF ( " \t %S " , age . c_str ( ) ) ;
delete [ ] ageName ;
temp = " \t " + temp + " \n " ;
fLog - > AddLine ( temp . c_str ( ) ) ;
std : : vector < std : : wstring > sets = GetSetList ( ages [ i ] ) ;
WStringVector sets = GetSetList ( age ) ;
for ( WStringVector : : iterator j = sets . begin ( ) ; j ! = sets . end ( ) ; + + j )
for ( int j = 0 ; j < sets . size ( ) ; j + + )
{
{
char * setName = hsWStringToString ( sets [ j ] . c_str ( ) ) ;
std : : wstring set = ( * j ) ;
std : : string temp = setName ;
fLog - > AddLineF ( " \t \t %S " , set . c_str ( ) ) ;
delete [ ] setName ;
temp = " \t \t " + temp + " \n " ;
fLog - > AddLine ( temp . c_str ( ) ) ;
std : : vector < std : : wstring > names = GetElementList ( ages [ i ] , sets [ j ] ) ;
WStringVector names = GetElementList ( age , set ) ;
for ( WStringVector : : iterator k = names . begin ( ) ; k ! = names . end ( ) ; + + k )
for ( int k = 0 ; k < names . size ( ) ; k + + )
{
{
char * elemName = hsWStringToString ( names [ k ] . c_str ( ) ) ;
std : : wstring name = ( * k ) ;
std : : string temp = elemName ;
fLog - > AddLineF ( " \t \t \t %S " , name . c_str ( ) ) ;
delete [ ] elemName ;
temp = " \t \t \t " + temp + " \n " ;
fLog - > AddLine ( temp . c_str ( ) ) ;
}
}
}
}
}
}