From bde2b14fdf6382c72ef0efc850c484bd2f735c4e Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Fri, 20 Apr 2012 16:38:52 -0700 Subject: [PATCH 1/6] Use plString in pfLocalizationMgr. Conflicts: Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h --- .../pfLocalizationDataMgr.cpp | 406 ++++++++---------- .../pfLocalizationMgr/pfLocalizationDataMgr.h | 76 ++-- .../pfLocalizationMgr/pfLocalizationMgr.cpp | 8 +- .../pfLocalizationMgr/pfLocalizationMgr.h | 4 +- .../pfLocalizationMgr/pfLocalizedString.cpp | 92 ++-- .../pfLocalizationMgr/pfLocalizedString.h | 35 +- 6 files changed, 277 insertions(+), 344 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index d961d12c..cf9ee052 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -84,34 +84,34 @@ public: static void XMLCALL HandleData(void *userData, const XML_Char *data, int stringLength); friend class LocalizationDatabase; - // first wstring is language, second is data - typedef std::map element; + // first string is language, second is data + typedef std::map element; - // the wstring is the element name - typedef std::map set; + // the string is the element name + typedef std::map set; - // the wstring is the set name - typedef std::map age; + // the string is the set name + typedef std::map age; - // the wstring is the age name - typedef std::map ageMap; + // the string is the age name + typedef std::map ageMap; protected: bool fWeExploded; // alternative to massive error stack - std::string fFilename; + plString fFilename; XML_Parser fParser; struct tagInfo { - std::wstring fTag; - std::map fAttributes; + plString fTag; + std::map fAttributes; }; std::stack fTagStack; int fSkipDepth; // if we need to skip a block, this is the depth we need to skip to bool fIgnoreContents; // are we ignoring the contents between tags? - std::wstring fCurrentAge, fCurrentSet, fCurrentElement, fCurrentTranslation; + plString fCurrentAge, fCurrentSet, fCurrentElement, fCurrentTranslation; ageMap fData; @@ -126,8 +126,8 @@ protected: public: LocalizationXMLFile() : fWeExploded(false), fFilename("") { } - bool Parse(const std::string & fileName); // returns false on failure - void AddError(const plString& errorText); + bool Parse(const plString & fileName); // returns false on failure + void AddError(const plString & errorText); }; // A few small helper structs @@ -177,12 +177,12 @@ XML_Memory_Handling_Suite gHeapAllocator = { //metmet remove static void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *element, const XML_Char **attributes) { - std::wstring wElement = element; + plString wElement = plString::FromWchar(element); LocalizationXMLFile *file = (LocalizationXMLFile*)userData; - std::map wAttributes; + std::map wAttributes; for (int i = 0; attributes[i]; i += 2) - wAttributes[attributes[i]] = attributes[i+1]; + wAttributes[plString::FromWchar(static_cast(attributes[i]))] = plString::FromWchar(static_cast(attributes[i+1])); LocalizationXMLFile::tagInfo parentTag; if (!file->fTagStack.empty()) @@ -198,15 +198,15 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme return; // now we handle this tag - if (wElement == L"localizations") + if (wElement == "localizations") file->IHandleLocalizationsTag(parentTag, newTag); - else if (wElement == L"age") + else if (wElement == "age") file->IHandleAgeTag(parentTag, newTag); - else if (wElement == L"set") + else if (wElement == "set") file->IHandleSetTag(parentTag, newTag); - else if (wElement == L"element") + else if (wElement == "element") file->IHandleElementTag(parentTag, newTag); - else if (wElement == L"translation") + else if (wElement == "translation") file->IHandleTranslationTag(parentTag, newTag); else file->AddError(plString::Format("Unknown tag %S found", wElement.c_str())); @@ -214,7 +214,7 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme //metmet remove static and include the function inside LocalizationXMLFile void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element) { - std::wstring wElement = element; + plString wElement = plString::FromWchar(element); LocalizationXMLFile *file = (LocalizationXMLFile*)userData; if (file->fSkipDepth != -1) // we're currently skipping @@ -224,16 +224,16 @@ void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element file->fSkipDepth = -1; // we're done skipping } - if (wElement == L"age") // we left the age block - file->fCurrentAge = L""; - else if (wElement == L"set") // we left the set block - file->fCurrentSet = L""; - else if (wElement == L"element") // we left the element block - file->fCurrentElement = L""; - else if (wElement == L"translation") // we left the translation block + if (wElement == "age") // we left the age block + file->fCurrentAge = ""; + else if (wElement == "set") // we left the set block + file->fCurrentSet = ""; + else if (wElement == "element") // we left the element block + file->fCurrentElement = ""; + else if (wElement == "translation") // we left the translation block { file->fIgnoreContents = true; - file->fCurrentTranslation = L""; + file->fCurrentTranslation = ""; } file->fTagStack.pop(); @@ -249,7 +249,7 @@ void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *dat // 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) - std::wstring wData = std::wstring(data, stringLength); + plString wData = plString::FromWchar(data); // 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; @@ -265,7 +265,7 @@ void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *dat void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { - if (parentTag.fTag != L"") // we only allow tags at root level + if (parentTag.fTag != "") // we only allow tags at root level { AddError("localizations tag only allowed at root level"); return; @@ -277,20 +277,20 @@ void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tag void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { // it has to be inside the subtitles tag - if (parentTag.fTag != L"localizations") + if (parentTag.fTag != "localizations") { AddError("age tag can only be directly inside a localizations tag"); return; } // we have to have a name attribute - if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) + if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) { AddError("age tag is missing the name attribute"); return; } - fCurrentAge = thisTag.fAttributes.find(L"name")->second; + fCurrentAge = thisTag.fAttributes.find("name")->second; } //// IHandleSetTag() ///////////////////////////////////////////////// @@ -298,20 +298,20 @@ void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & par void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { // it has to be inside the age tag - if (parentTag.fTag != L"age") + if (parentTag.fTag != "age") { AddError("set tag can only be directly inside a age tag"); return; } // we have to have a name attribute - if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) + if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) { AddError("set tag is missing the name attribute"); return; } - fCurrentSet = thisTag.fAttributes.find(L"name")->second; + fCurrentSet = thisTag.fAttributes.find("name")->second; } //// IHandleElementTag() ///////////////////////////////////////////// @@ -319,20 +319,20 @@ void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & par void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { // it has to be inside the element tag - if (parentTag.fTag != L"set") + if (parentTag.fTag != "set") { AddError("element tag can only be directly inside a set tag"); return; } // we have to have a name attribute - if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) + if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) { AddError("element tag is missing the name attribute"); return; } - fCurrentElement = thisTag.fAttributes.find(L"name")->second; + fCurrentElement = thisTag.fAttributes.find("name")->second; } //// IHandleTranslationTag() ///////////////////////////////////////// @@ -340,36 +340,36 @@ void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo & void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { // it has to be inside the element tag - if (parentTag.fTag != L"element") + if (parentTag.fTag != "element") { AddError("translation tag can only be directly inside a element tag"); return; } // we have to have a language attribute - if (thisTag.fAttributes.find(L"language") == thisTag.fAttributes.end()) + if (thisTag.fAttributes.find("language") == thisTag.fAttributes.end()) { AddError("translation tag is missing the language attribute"); return; } fIgnoreContents = false; // we now want contents between tags - fCurrentTranslation = thisTag.fAttributes.find(L"language")->second; + fCurrentTranslation = thisTag.fAttributes.find("language")->second; } //// Parse() ///////////////////////////////////////////////////////// -bool LocalizationXMLFile::Parse(const std::string & fileName) +bool LocalizationXMLFile::Parse(const plString & fileName) { fFilename = fileName; while (!fTagStack.empty()) fTagStack.pop(); - fCurrentAge = L""; - fCurrentSet = L""; - fCurrentElement = L""; - fCurrentTranslation = L""; + fCurrentAge = ""; + fCurrentSet = ""; + fCurrentElement = ""; + fCurrentTranslation = ""; fIgnoreContents = true; fSkipDepth = -1; @@ -390,7 +390,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName) hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str()); if (!xmlStream) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.c_str()); + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %S", fileName.c_str()); return false; } @@ -424,7 +424,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName) void LocalizationXMLFile::AddError(const plString& errorText) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR (line %d): %s", + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR (line %d): %S", XML_GetCurrentLineNumber(fParser), errorText.c_str()); fSkipDepth = fTagStack.size(); // skip this block fWeExploded = true; @@ -442,27 +442,27 @@ void LocalizationXMLFile::AddError(const plString& errorText) class LocalizationDatabase { protected: - std::string fDirectory; // the directory we're supposed to parse + plString fDirectory; // the directory we're supposed to parse + plString fErrorString; // total sum of all errors encountered (also has warnings and status messages) std::vector fFiles; // the various XML files in that directory LocalizationXMLFile::ageMap fData; - LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const std::wstring & fileName, const std::wstring & path); - LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const std::wstring & fileName, const std::wstring & path); - LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const std::wstring & fileName, const std::wstring & path); + LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path); + LocalizationXMLFile::set IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path); + LocalizationXMLFile::age IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path); void IMergeData(); // merge all localization data in the files - void IVerifyElement(const std::wstring &ageName, const std::wstring &setName, LocalizationXMLFile::set::iterator& curElement); - void IVerifySet(const std::wstring &ageName, const std::wstring &setName); - void IVerifyAge(const std::wstring &ageName); + void IVerifyElement(const plString &ageName, const plString &setName, LocalizationXMLFile::set::iterator& curElement); + void IVerifySet(const plString &ageName, const plString &setName); + void IVerifyAge(const plString &ageName); void IVerifyData(); // verify the localization data once it has been merged in public: LocalizationDatabase() {} - void Parse(const std::string & directory); - + void Parse(const plString & directory); LocalizationXMLFile::ageMap GetData() {return fData;} }; @@ -472,7 +472,7 @@ public: //// IMergeElementData /////////////////////////////////////////////// -LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const std::wstring & fileName, const std::wstring & path) +LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, const plString & fileName, const plString & path) { // copy the data over, alerting the user to any duplicate translations LocalizationXMLFile::element::iterator curTranslation; @@ -492,7 +492,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio //// IMergeSetData /////////////////////////////////////////////////// -LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const std::wstring & fileName, const std::wstring & path) +LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile::set firstSet, LocalizationXMLFile::set secondSet, const plString & fileName, const plString & path) { // Merge all the elements LocalizationXMLFile::set::iterator curElement; @@ -502,7 +502,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile if (firstSet.find(curElement->first) == firstSet.end()) firstSet[curElement->first] = curElement->second; else // merge the element in - firstSet[curElement->first] = IMergeElementData(firstSet[curElement->first], curElement->second, fileName, path + L"." + curElement->first); + firstSet[curElement->first] = IMergeElementData(firstSet[curElement->first], curElement->second, fileName, path + "." + curElement->first); } return firstSet; @@ -510,7 +510,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile //// IMergeAgeData /////////////////////////////////////////////////// -LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const std::wstring & fileName, const std::wstring & path) +LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile::age firstAge, LocalizationXMLFile::age secondAge, const plString & fileName, const plString & path) { // Merge all the sets LocalizationXMLFile::age::iterator curSet; @@ -520,7 +520,7 @@ LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile if (firstAge.find(curSet->first) == firstAge.end()) firstAge[curSet->first] = curSet->second; else // merge the data in - firstAge[curSet->first] = IMergeSetData(firstAge[curSet->first], curSet->second, fileName, path + L"." + curSet->first); + firstAge[curSet->first] = IMergeSetData(firstAge[curSet->first], curSet->second, fileName, path + "." + curSet->first); } return firstAge; @@ -532,11 +532,6 @@ void LocalizationDatabase::IMergeData() { for (int i = 0; i < fFiles.size(); i++) { - std::wstring wFilename; - wchar_t *buff = hsStringToWString(fFiles[i].fFilename.c_str()); - wFilename = buff; - delete [] buff; - LocalizationXMLFile::ageMap fileData = fFiles[i].fData; LocalizationXMLFile::ageMap::iterator curAge; for (curAge = fileData.begin(); curAge != fileData.end(); curAge++) @@ -545,29 +540,27 @@ void LocalizationDatabase::IMergeData() if (fData.find(curAge->first) == fData.end()) fData[curAge->first] = curAge->second; else // otherwise, merge the data in - fData[curAge->first] = IMergeAgeData(fData[curAge->first], curAge->second, wFilename, curAge->first); + fData[curAge->first] = IMergeAgeData(fData[curAge->first], curAge->second, fFiles[i].fFilename, curAge->first); } } } //// IVerifyElement() //////////////////////////////////////////////// -void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std::wstring &setName, LocalizationXMLFile::set::iterator& curElement) +void LocalizationDatabase::IVerifyElement(const plString &ageName, const plString &setName, LocalizationXMLFile::set::iterator& curElement) { - WStringVector languageNames; - std::wstring defaultLanguage; + std::vector languageNames; + plString defaultLanguage; int numLocales = plLocalization::GetNumLocales(); for (int curLocale = 0; curLocale <= numLocales; curLocale++) { - const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); - wchar_t *wName = hsStringToWString(name); - languageNames.push_back(wName); - delete [] wName; + plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); + languageNames.push_back(name); } defaultLanguage = languageNames[0]; - std::wstring elementName = curElement->first; + plString elementName = curElement->first; LocalizationXMLFile::element& theElement = curElement->second; LocalizationXMLFile::element::iterator curTranslation = theElement.begin(); @@ -606,13 +599,12 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std //// IVerifySet() //////////////////////////////////////////////////// -void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::wstring &setName) +void LocalizationDatabase::IVerifySet(const plString &ageName, const plString &setName) { LocalizationXMLFile::set& theSet = fData[ageName][setName]; LocalizationXMLFile::set::iterator curElement = theSet.begin(); - wchar_t *wDefLang = hsStringToWString(plLocalization::GetLanguageName((plLocalization::Language)0)); - std::wstring defaultLanguage = wDefLang; - delete [] wDefLang; + + plString defaultLanguage = plLocalization::GetLanguageName((plLocalization::Language)0); while (curElement != theSet.end()) { @@ -633,7 +625,7 @@ void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::ws //// IVerifyAge() //////////////////////////////////////////////////// -void LocalizationDatabase::IVerifyAge(const std::wstring &ageName) +void LocalizationDatabase::IVerifyAge(const plString &ageName) { LocalizationXMLFile::age& theAge = fData[ageName]; LocalizationXMLFile::age::iterator curSet; @@ -652,13 +644,13 @@ void LocalizationDatabase::IVerifyData() //// Parse() ///////////////////////////////////////////////////////// -void LocalizationDatabase::Parse(const std::string & directory) +void LocalizationDatabase::Parse(const plString & directory) { fDirectory = directory; fFiles.clear(); char filename[255]; - hsFolderIterator xmlFolder((directory+PATH_SEPARATOR_STR).c_str()); + hsFolderIterator xmlFolder((directory + PATH_SEPARATOR_STR).c_str()); while(xmlFolder.NextFileSuffix(".loc")) { xmlFolder.GetPathAndName(filename); @@ -685,30 +677,32 @@ void LocalizationDatabase::Parse(const std::string & directory) //// ISplitString() ////////////////////////////////////////////////// template -void pfLocalizationDataMgr::pf3PartMap::ISplitString(std::wstring key, std::wstring &age, std::wstring &set, std::wstring &name) +void pfLocalizationDataMgr::pf3PartMap::ISplitString(plString key, plString &age, plString &set, plString &name) { - std::wstring::size_type periodLoc = key.find(L"."); - age = key.substr(0, periodLoc); - if (periodLoc >= key.length()) + int periodLoc = key.Find("."); + age = key.Substr(0, periodLoc); + if (periodLoc >= key.GetSize()) { return; // don't get set or name if there isn't any period + } - key = key.substr(periodLoc + 1, key.length()); - periodLoc = key.find(L"."); - set = key.substr(0, periodLoc); - if (periodLoc >= key.length()) + key = key.Substr(periodLoc + 1, key.GetSize()); + periodLoc = key.Find("."); + set = key.Substr(0, periodLoc); + if (periodLoc >= key.GetSize()) { return; // don't get name if there isn't another period + } - name = key.substr(periodLoc + 1, key.length()); + name = key.Substr(periodLoc + 1, key.GetSize()); } //// exists() //////////////////////////////////////////////////////// template -bool pfLocalizationDataMgr::pf3PartMap::exists(const std::wstring & key) +bool pfLocalizationDataMgr::pf3PartMap::exists(const plString & key) { - std::wstring age, set, name; + plString age, set, name; ISplitString(key, age, set, name); - if (age == L"" || set == L"" || name == L"") // if any are missing, it's invalid, so we don't have it + if (age == "" || set == "" || name == "") // if any are missing, it's invalid, so we don't have it return false; // now check individually @@ -726,11 +720,11 @@ bool pfLocalizationDataMgr::pf3PartMap::exists(const std::wstring & key) //// setExists() ///////////////////////////////////////////////////// template -bool pfLocalizationDataMgr::pf3PartMap::setExists(const std::wstring & key) +bool pfLocalizationDataMgr::pf3PartMap::setExists(const plString & key) { - std::wstring age, set, name; + plString age, set, name; ISplitString(key, age, set, name); - if (age == L"" || set == L"") // if any are missing, it's invalid, so we don't have it (ignoring name) + if (age == "" || set == "") // if any are missing, it's invalid, so we don't have it (ignoring name) return false; // now check individually @@ -746,11 +740,11 @@ bool pfLocalizationDataMgr::pf3PartMap::setExists(const std::wstring & key //// erase() ///////////////////////////////////////////////////////// template -void pfLocalizationDataMgr::pf3PartMap::erase(const std::wstring & key) +void pfLocalizationDataMgr::pf3PartMap::erase(const plString & key) { - std::wstring age, set, name; + plString age, set, name; ISplitString(key, age, set, name); - if (age == L"" || set == L"" || name == L"") // if any are missing, it's invalid, so we don't delete it + if (age == "" || set == "" || name == "") // if any are missing, it's invalid, so we don't delete it return; // now check individually @@ -772,9 +766,9 @@ void pfLocalizationDataMgr::pf3PartMap::erase(const std::wstring & key) //// operator[]() //////////////////////////////////////////////////// template -mapT &pfLocalizationDataMgr::pf3PartMap::operator[](const std::wstring &key) +mapT &pfLocalizationDataMgr::pf3PartMap::operator[](const plString &key) { - std::wstring age, set, name; + plString age, set, name; ISplitString(key, age, set, name); return fData[age][set][name]; } @@ -782,9 +776,9 @@ mapT &pfLocalizationDataMgr::pf3PartMap::operator[](const std::wstring &ke //// getAgeList() //////////////////////////////////////////////////// template -WStringVector pfLocalizationDataMgr::pf3PartMap::getAgeList() +std::vector pfLocalizationDataMgr::pf3PartMap::getAgeList() { - WStringVector retVal; + std::vector retVal; typename ThreePartMap::iterator curAge; for (curAge = fData.begin(); curAge != fData.end(); curAge++) @@ -796,10 +790,10 @@ WStringVector pfLocalizationDataMgr::pf3PartMap::getAgeList() //// getSetList() //////////////////////////////////////////////////// template -WStringVector pfLocalizationDataMgr::pf3PartMap::getSetList(const std::wstring & age) +std::vector pfLocalizationDataMgr::pf3PartMap::getSetList(const plString & age) { - WStringVector retVal; - typename std::map >::iterator curSet; + std::vector retVal; + typename std::map >::iterator curSet; if (fData.find(age) == fData.end()) return retVal; // return an empty list, the age doesn't exist @@ -813,10 +807,10 @@ WStringVector pfLocalizationDataMgr::pf3PartMap::getSetList(const std::wst //// getNameList() /////////////////////////////////////////////////// template -WStringVector pfLocalizationDataMgr::pf3PartMap::getNameList(const std::wstring & age, const std::wstring & set) +std::vector pfLocalizationDataMgr::pf3PartMap::getNameList(const plString & age, const plString & set) { - WStringVector retVal; - typename std::map::iterator curName; + std::vector retVal; + typename std::map::iterator curName; if (fData.find(age) == fData.end()) return retVal; // return an empty list, the age doesn't exist @@ -839,7 +833,7 @@ plStatusLog *pfLocalizationDataMgr::fLog = nil; // output logfile //// Constructor/Destructor ////////////////////////////////////////// -pfLocalizationDataMgr::pfLocalizationDataMgr(const std::string & path) +pfLocalizationDataMgr::pfLocalizationDataMgr(const plString & path) { hsAssert(!fInstance, "Tried to create the localization data manager more than once!"); fInstance = this; @@ -869,10 +863,8 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE for (int curLocale = 0; curLocale <= numLocales; curLocale++) { - const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); - wchar_t *wName = hsStringToWString(name); - retVal[wName] = L""; - delete [] wName; + plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); + retVal[name] = ""; } return retVal; @@ -880,29 +872,23 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE //// IGetCurrentLanguageName ///////////////////////////////////////// -std::wstring pfLocalizationDataMgr::IGetCurrentLanguageName() +plString pfLocalizationDataMgr::IGetCurrentLanguageName() { - std::wstring retVal; - const char *name = plLocalization::GetLanguageName(plLocalization::GetLanguage()); - wchar_t *wName = hsStringToWString(name); - retVal = wName; - delete [] wName; + plString retVal = plLocalization::GetLanguageName(plLocalization::GetLanguage()); return retVal; } //// IGetAllLanguageNames //////////////////////////////////////////// -WStringVector pfLocalizationDataMgr::IGetAllLanguageNames() +std::vector pfLocalizationDataMgr::IGetAllLanguageNames() { int numLocales = plLocalization::GetNumLocales(); - WStringVector retVal; + std::vector retVal; for (int curLocale = 0; curLocale <= numLocales; curLocale++) { - const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); - wchar_t *wName = hsStringToWString(name); - retVal.push_back(wName); - delete [] wName; + plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); + retVal.push_back(name); } return retVal; @@ -910,7 +896,7 @@ WStringVector pfLocalizationDataMgr::IGetAllLanguageNames() //// IConvertSubtitle //////////////////////////////////////////////// -void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const std::wstring & curPath) +void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const plString & curPath) { pfLocalizationDataMgr::localizedElement newElement; int16_t numArgs = -1; @@ -931,7 +917,7 @@ void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const s //// IConvertSet ///////////////////////////////////////////////////// -void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const std::wstring & curPath) +void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const plString & curPath) { LocalizationXMLFile::set::iterator curElement; for (curElement = setInfo->fSet.begin(); curElement != setInfo->fSet.end(); curElement++) @@ -939,13 +925,13 @@ void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const std::wstring LocElementInfo elementInfo; elementInfo.fElement = curElement->second; - IConvertElement(&elementInfo, curPath + L"." + curElement->first); + IConvertElement(&elementInfo, plString::Format("%S.%S", curPath.c_str(), curElement->first.c_str())); } } //// IConvertAge ///////////////////////////////////////////////////// -void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const std::wstring & curPath) +void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const plString & curPath) { LocalizationXMLFile::age::iterator curSet; for (curSet = ageInfo->fAge.begin(); curSet != ageInfo->fAge.end(); curSet++) @@ -953,98 +939,70 @@ void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const std::wstring LocSetInfo setInfo; setInfo.fSet = curSet->second; - IConvertSet(&setInfo, curPath + L"." + curSet->first); - } -} - -//// IConvertToByteStream //////////////////////////////////////////// - -char *pfLocalizationDataMgr::IConvertToByteStream(const std::wstring & data, uint32_t &len) -{ - len = data.length() * 2 + 2; // each wchar_t is two chars and add two bytes for the header - char *retVal = new char[len]; // we don't add an extra byte for the 0 because the parser doesn't need it - char lowByte = 0, highByte = 0; - retVal[0] = (char)0xFF; // insert FFFE for little-endian UTF-16 (big-endian would be FEFF) - retVal[1] = (char)0xFE; - int curByteStreamPos = 2; - for (int curLoc = 0; curLoc < data.length(); curLoc++) - { - wchar_t curChar = data[curLoc]; - lowByte = (char)(curChar & 0x00FF); - highByte = (char)((curChar & 0xFF00) >> 8); - - // since the data is AABBCCDD, we need to put in in our uint8_t stream as BBAADDCC - // (so it kinda looks backward because we're storing this as little-endian) - retVal[curByteStreamPos + 1] = highByte; - retVal[curByteStreamPos] = lowByte; - curByteStreamPos += 2; + IConvertSet(&setInfo, plString::Format("%S.%S", curPath.c_str(), curSet->first.c_str())); } - return retVal; } //// IWriteText ////////////////////////////////////////////////////// -void pfLocalizationDataMgr::IWriteText(const std::string & filename, const std::wstring & ageName, const std::wstring & languageName) +void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString & ageName, const plString & languageName) { bool weWroteData = false; // did we actually write any data of consequence? bool setEmpty = true; // we will try to pretty print it all so it's easy to read for the devs - std::wstring fileData = L"\n"; // stores the xml we are going to write to the file (UTF-16 format) - fileData += L"\n"; - fileData += L"\t\n"; + plStringStream fileData; + fileData << "\n"; // stores the xml we are going to write to the file (UTF-16 format) + fileData << "\n"; + fileData << plString::Format("\t\n", ageName.c_str()); - WStringVector setNames = GetSetList(ageName); + std::vector setNames = GetSetList(ageName); for (int curSet = 0; curSet < setNames.size(); curSet++) { setEmpty = true; // so far, this set is empty - std::wstring setCode = L""; - setCode += L"\t\t\n"; + plStringStream setCode; + setCode << plString::Format("\t\t\n", setNames[curSet].c_str()); - WStringVector elementNames = GetElementList(ageName, setNames[curSet]); + std::vector elementNames = GetElementList(ageName, setNames[curSet]); for (int curElement = 0; curElement < elementNames.size(); curElement++) { - setCode += L"\t\t\t\n"; - std::wstring key = ageName + L"." + setNames[curSet] + L"." + elementNames[curElement]; + setCode << plString::Format("\t\t\t\n", elementNames[curElement].c_str()); + plString key = plString::Format("%S.%S.%S", ageName.c_str(), setNames[curSet].c_str(), elementNames[curElement].c_str()); if (fLocalizedElements[key].find(languageName) != fLocalizedElements[key].end()) { - std::wstring key = ageName + L"." + setNames[curSet] + L"." + elementNames[curElement]; weWroteData = true; setEmpty = false; - setCode += L"\t\t\t\t"; - setCode += fLocalizedElements[key][languageName].ToXML(); - setCode += L"\n"; + setCode << plString::Format("\t\t\t\t", languageName.c_str()); + setCode << fLocalizedElements[key][languageName].ToXML(); + setCode << "\n"; } - setCode += L"\t\t\t\n"; + setCode << "\t\t\t\n"; } - setCode += L"\t\t\n"; + setCode << "\t\t\n"; if (!setEmpty) - fileData += setCode; + fileData << setCode.GetString(); } - fileData += L"\t\n"; - fileData += L"\n"; + fileData << "\t\n"; + fileData << "\n"; if (weWroteData) { // now spit the results out to the file - uint32_t numBytes; - char *byteStream = IConvertToByteStream(fileData, numBytes); hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename.c_str()); - xmlStream->Write(numBytes, byteStream); + xmlStream->Write(fileData.GetLength(), fileData.GetString().c_str()); xmlStream->Close(); delete xmlStream; - delete [] byteStream; } } //// Initialize ////////////////////////////////////////////////////// -void pfLocalizationDataMgr::Initialize(const std::string & path) +void pfLocalizationDataMgr::Initialize(const plString & path) { if (fInstance) return; @@ -1102,17 +1060,17 @@ void pfLocalizationDataMgr::SetupData() //// GetElement ////////////////////////////////////////////////////// -pfLocalizedString pfLocalizationDataMgr::GetElement(const std::wstring & name) +pfLocalizedString pfLocalizationDataMgr::GetElement(const plString & name) { pfLocalizedString retVal; // if this returns before we initialize it, it will be empty, indicating failure if (!fLocalizedElements.exists(name)) // does the requested element exist? return retVal; // nope, so return failure - std::wstring languageName = IGetCurrentLanguageName(); + plString languageName = IGetCurrentLanguageName(); if (fLocalizedElements[name].find(languageName) == fLocalizedElements[name].end()) // current language isn't specified { - languageName = L"English"; // force to english + languageName = "English"; // force to english if (fLocalizedElements[name].find(languageName) == fLocalizedElements[name].end()) // make sure english exists return retVal; // language doesn't exist } @@ -1122,7 +1080,7 @@ pfLocalizedString pfLocalizationDataMgr::GetElement(const std::wstring & name) //// GetSpecificElement ////////////////////////////////////////////// -pfLocalizedString pfLocalizationDataMgr::GetSpecificElement(const std::wstring & name, const std::wstring & language) +pfLocalizedString pfLocalizationDataMgr::GetSpecificElement(const plString & name, const plString & language) { pfLocalizedString retVal; // if this returns before we initialize it, it will have an ID of 0, indicating failure @@ -1138,10 +1096,10 @@ pfLocalizedString pfLocalizationDataMgr::GetSpecificElement(const std::wstring & //// GetLanguages //////////////////////////////////////////////////// -WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, const std::wstring & setName, const std::wstring & elementName) +std::vector pfLocalizationDataMgr::GetLanguages(const plString & ageName, const plString & setName, const plString & elementName) { - WStringVector retVal; - std::wstring key = ageName + L"." + setName + L"." + elementName; + std::vector retVal; + plString key = plString::Format("%S.%S.%S", ageName.c_str(), setName.c_str(), elementName.c_str()); if (fLocalizedElements.exists(key)) { // age, set, and element exists @@ -1149,8 +1107,8 @@ WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, localizedElement::iterator curLanguage; for (curLanguage = elem.begin(); curLanguage != elem.end(); curLanguage++) { - std::wstring language = curLanguage->first; - if (!language.empty()) // somehow blank language names sneak in... so don't return them + plString language = curLanguage->first; + if (!language.IsEmpty()) // somehow blank language names sneak in... so don't return them retVal.push_back(curLanguage->first); } } @@ -1159,9 +1117,9 @@ WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, //// GetElementXMLData /////////////////////////////////////////////// -std::wstring pfLocalizationDataMgr::GetElementXMLData(const std::wstring & name, const std::wstring & languageName) +plString pfLocalizationDataMgr::GetElementXMLData(const plString & name, const plString & languageName) { - std::wstring retVal = L""; + plString retVal = ""; if (fLocalizedElements.exists(name)) { if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) @@ -1172,9 +1130,9 @@ std::wstring pfLocalizationDataMgr::GetElementXMLData(const std::wstring & name, //// GetElementPlainTextData ///////////////////////////////////////// -std::wstring pfLocalizationDataMgr::GetElementPlainTextData(const std::wstring & name, const std::wstring & languageName) +plString pfLocalizationDataMgr::GetElementPlainTextData(const plString & name, const plString & languageName) { - std::wstring retVal = L""; + plString retVal = ""; if (fLocalizedElements.exists(name)) { if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) @@ -1185,7 +1143,7 @@ std::wstring pfLocalizationDataMgr::GetElementPlainTextData(const std::wstring & //// SetElementXMLData /////////////////////////////////////////////// -bool pfLocalizationDataMgr::SetElementXMLData(const std::wstring & name, const std::wstring & languageName, const std::wstring & xmlData) +bool pfLocalizationDataMgr::SetElementXMLData(const plString & name, const plString & languageName, const plString & xmlData) { if (!fLocalizedElements.exists(name)) return false; // doesn't exist @@ -1196,7 +1154,7 @@ bool pfLocalizationDataMgr::SetElementXMLData(const std::wstring & name, const s //// SetElementPlainTextData ///////////////////////////////////////// -bool pfLocalizationDataMgr::SetElementPlainTextData(const std::wstring & name, const std::wstring & languageName, const std::wstring & plainText) +bool pfLocalizationDataMgr::SetElementPlainTextData(const plString & name, const plString & languageName, const plString & plainText) { if (!fLocalizedElements.exists(name)) return false; // doesn't exist @@ -1207,31 +1165,31 @@ bool pfLocalizationDataMgr::SetElementPlainTextData(const std::wstring & name, c //// AddLocalization ///////////////////////////////////////////////// -bool pfLocalizationDataMgr::AddLocalization(const std::wstring & name, const std::wstring & newLanguage) +bool pfLocalizationDataMgr::AddLocalization(const plString & name, const plString & newLanguage) { if (!fLocalizedElements.exists(name)) return false; // doesn't exist // copy the english over so it can be localized - fLocalizedElements[name][newLanguage] = fLocalizedElements[name][L"English"]; + fLocalizedElements[name][newLanguage] = fLocalizedElements[name]["English"]; return true; } //// AddElement ////////////////////////////////////////////////////// -bool pfLocalizationDataMgr::AddElement(const std::wstring & name) +bool pfLocalizationDataMgr::AddElement(const plString & name) { if (fLocalizedElements.exists(name)) return false; // already exists pfLocalizedString newElement; - fLocalizedElements[name][L"English"] = newElement; + fLocalizedElements[name]["English"] = newElement; return true; } //// DeleteLocalization ////////////////////////////////////////////// -bool pfLocalizationDataMgr::DeleteLocalization(const std::wstring & name, const std::wstring & languageName) +bool pfLocalizationDataMgr::DeleteLocalization(const plString & name, const plString & languageName) { if (!fLocalizedElements.exists(name)) return false; // doesn't exist @@ -1245,7 +1203,7 @@ bool pfLocalizationDataMgr::DeleteLocalization(const std::wstring & name, const //// DeleteElement /////////////////////////////////////////////////// -bool pfLocalizationDataMgr::DeleteElement(const std::wstring & name) +bool pfLocalizationDataMgr::DeleteElement(const plString & name) { if (!fLocalizedElements.exists(name)) return false; // doesn't exist @@ -1257,24 +1215,16 @@ bool pfLocalizationDataMgr::DeleteElement(const std::wstring & name) //// WriteDatabaseToDisk ///////////////////////////////////////////// -void pfLocalizationDataMgr::WriteDatabaseToDisk(const std::string & path) +void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) { // first, write the styles and panel settings to styles.sub - WStringVector ageNames = GetAgeList(); - WStringVector languageNames = IGetAllLanguageNames(); + std::vector ageNames = GetAgeList(); + std::vector languageNames = IGetAllLanguageNames(); for (int curAge = 0; curAge < ageNames.size(); curAge++) { for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++) { - std::string cAgeName, cLanguageName; - char *temp = hsWStringToString(ageNames[curAge].c_str()); - cAgeName = temp; - delete [] temp; - temp = hsWStringToString(languageNames[curLanguage].c_str()); - cLanguageName = temp; - delete [] temp; - - IWriteText(path + "/" + cAgeName + cLanguageName + ".loc", ageNames[curAge], languageNames[curLanguage]); + IWriteText(plString::Format("%S/%S%S.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]); } } } @@ -1283,26 +1233,26 @@ void pfLocalizationDataMgr::WriteDatabaseToDisk(const std::string & path) void pfLocalizationDataMgr::OutputTreeToLog() { - WStringVector ages = GetAgeList(); + std::vector ages = GetAgeList(); fLog->AddLine("\n"); fLog->AddLine("Localization tree:\n"); - for (WStringVector::iterator i = ages.begin(); i != ages.end(); ++i) + for (std::vector::iterator i = ages.begin(); i != ages.end(); ++i) { - std::wstring age = *i; + plString age = *i; fLog->AddLineF("\t%S", age.c_str()); - WStringVector sets = GetSetList(age); - for (WStringVector::iterator j = sets.begin(); j != sets.end(); ++j) + std::vector sets = GetSetList(age); + for (std::vector::iterator j = sets.begin(); j != sets.end(); ++j) { - std::wstring set = (*j); + plString set = (*j); fLog->AddLineF("\t\t%S", set.c_str()); - WStringVector names = GetElementList(age, set); - for (WStringVector::iterator k = names.begin(); k != names.end(); ++k) + std::vector names = GetElementList(age, set); + for (std::vector::iterator k = names.begin(); k != names.end(); ++k) { - std::wstring name = (*k); + plString name = (*k); fLog->AddLineF("\t\t\t%S", name.c_str()); } } diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h index fbbc7832..52b2ec03 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h @@ -55,6 +55,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfLocalizedString.h" class plStatusLog; +class plString; // Helper classes/structs that are only used in this main class class LocalizationDatabase; @@ -81,49 +82,48 @@ protected: { protected: // Outer map is Age, then Set, finally Name - typedef std::map > > ThreePartMap; + typedef std::map > > ThreePartMap; ThreePartMap fData; - void ISplitString(std::wstring key, std::wstring &age, std::wstring &set, std::wstring &name); + void ISplitString(plString key, plString &age, plString &set, plString &name); public: // We will just have very basic functionality - bool exists(const std::wstring & key); // returns true if the key exists - bool setExists(const std::wstring & key); // returns true if the age.set exists (ignores name if passed in) - void erase(const std::wstring & key); // erases the key from the map + bool exists(const plString & key); // returns true if the key exists + bool setExists(const plString & key); // returns true if the age.set exists (ignores name if passed in) + void erase(const plString & key); // erases the key from the map - mapT &operator[](const std::wstring &key); // returns the item referenced by the key (and creates if necessary) + mapT &operator[](const plString &key); // returns the item referenced by the key (and creates if necessary) - WStringVector getAgeList(); // returns a list of all ages in this map - WStringVector getSetList(const std::wstring & age); // returns a list of all sets in the specified age - WStringVector getNameList(const std::wstring & age, const std::wstring & set); + std::vector getAgeList(); // returns a list of all ages in this map + std::vector getSetList(const plString & age); // returns a list of all sets in the specified age + std::vector getNameList(const plString & age, const plString & set); }; LocalizationDatabase *fDatabase; - typedef std::map localizedElement; + typedef std::map localizedElement; // Contains all localized strings, the key is the Age.Set.Name specified by XML, in localizedElement, the key is the language string pf3PartMap fLocalizedElements; - std::string fDataPath; + plString fDataPath; localizedElement ICreateLocalizedElement(); // ease of use function that creates a basic localized element object - std::wstring IGetCurrentLanguageName(); // get the name of the current language - WStringVector IGetAllLanguageNames(); + plString IGetCurrentLanguageName(); // get the name of the current language + std::vector IGetAllLanguageNames(); - void IConvertElement(LocElementInfo *elementInfo, const std::wstring & curPath); - void IConvertSet(LocSetInfo *setInfo, const std::wstring & curPath); - void IConvertAge(LocAgeInfo *ageInfo, const std::wstring & curPath); + void IConvertElement(LocElementInfo *elementInfo, const plString & curPath); + void IConvertSet(LocSetInfo *setInfo, const plString & curPath); + void IConvertAge(LocAgeInfo *ageInfo, const plString & curPath); - char *IConvertToByteStream(const std::wstring & data, uint32_t &len); // converts the wstring data to a string of bytes for file writing - void IWriteText(const std::string & filename, const std::wstring & ageName, const std::wstring & languageName); // Write localization text to the specified file + void IWriteText(const plString & filename, const plString & ageName, const plString & languageName); // Write localization text to the specified file - pfLocalizationDataMgr(const std::string & path); + pfLocalizationDataMgr(const plString & path); public: virtual ~pfLocalizationDataMgr(); - static void Initialize(const std::string & path); + static void Initialize(const plString & path); static void Shutdown(); static pfLocalizationDataMgr &Instance(void) {return *fInstance;} static bool InstanceValid(void) {return fInstance != nil;} @@ -131,32 +131,38 @@ public: void SetupData(); - pfLocalizedString GetElement(const std::wstring & name); - pfLocalizedString GetSpecificElement(const std::wstring & name, const std::wstring & languageName); + pfLocalizedString GetElement(const plString & name); + pfLocalizedString GetSpecificElement(const plString & name, const plString & languageName); - WStringVector GetAgeList() { return fLocalizedElements.getAgeList(); } - WStringVector GetSetList(const std::wstring & ageName) { return fLocalizedElements.getSetList(ageName); } - WStringVector GetElementList(const std::wstring & ageName, const std::wstring & setName) + std::vector GetAgeList() + { + return fLocalizedElements.getAgeList(); + } + std::vector GetSetList(const plString & ageName) + { + return fLocalizedElements.getSetList(ageName); + } + std::vector GetElementList(const plString & ageName, const plString & setName) { return fLocalizedElements.getNameList(ageName, setName); } - WStringVector GetLanguages(const std::wstring & ageName, const std::wstring & setName, const std::wstring & elementName); + std::vector GetLanguages(const plString & ageName, const plString & setName, const plString & elementName); - std::wstring GetElementXMLData(const std::wstring & name, const std::wstring & languageName); - std::wstring GetElementPlainTextData(const std::wstring & name, const std::wstring & languageName); + plString GetElementXMLData(const plString & name, const plString & languageName); + plString GetElementPlainTextData(const plString & name, const plString & languageName); // These convert the XML data to the actual subtitle and return true if successful (editor only) - bool SetElementXMLData(const std::wstring & name, const std::wstring & languageName, const std::wstring & xmlData); - bool SetElementPlainTextData(const std::wstring & name, const std::wstring & languageName, const std::wstring & plainText); + bool SetElementXMLData(const plString & name, const plString & languageName, const plString & xmlData); + bool SetElementPlainTextData(const plString & name, const plString & languageName, const plString & plainText); // Addition and deletion functions, return true if successful (editor only) - bool AddLocalization(const std::wstring & name, const std::wstring & newLanguage); - bool AddElement(const std::wstring & name); - bool DeleteLocalization(const std::wstring & name, const std::wstring & languageName); - bool DeleteElement(const std::wstring & name); + bool AddLocalization(const plString & name, const plString & newLanguage); + bool AddElement(const plString & name); + bool DeleteLocalization(const plString & name, const plString & languageName); + bool DeleteElement(const plString & name); // Writes the current database to the disk (editor only). It will create all the files and put them into path - void WriteDatabaseToDisk(const std::string & path); + void WriteDatabaseToDisk(const plString & path); void OutputTreeToLog(); // prints the localization tree to the log file }; diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp index a91eaa89..3d47e5fe 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp @@ -79,7 +79,7 @@ void pfLocalizationMgr::Initialize(const std::string & dataPath) return; fInstance = new pfLocalizationMgr(); - pfLocalizationDataMgr::Initialize(dataPath); // set up the data manager + pfLocalizationDataMgr::Initialize(dataPath.c_str()); // set up the data manager } //// Shutdown //////////////////////////////////////////////////////// @@ -95,13 +95,13 @@ void pfLocalizationMgr::Shutdown() //// GetString /////////////////////////////////////////////////////// -std::wstring pfLocalizationMgr::GetString(const std::wstring & path, const std::vector & args) +plString pfLocalizationMgr::GetString(const plString & path, const std::vector & args) { return pfLocalizationDataMgr::Instance().GetElement(path) % args; } -std::wstring pfLocalizationMgr::GetString(const std::wstring & path) +plString pfLocalizationMgr::GetString(const plString & path) { - std::vector args; // blank args so that % signs are still handled correctly + std::vector args; // blank args so that % signs are still handled correctly return pfLocalizationDataMgr::Instance().GetElement(path) % args; } diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h index ccb10063..e8df4234 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h @@ -70,8 +70,8 @@ public: // want the arguments in a different order (like you had to switch things around for a specific language) // then you use %1s, %2s, %3s and so on to specify arguments, these two cannot be mixed and you won't get // the results you expect if you do mix them. Path is specified by Age.Set.Name - std::wstring GetString(const std::wstring & path, const std::vector & args); - std::wstring GetString(const std::wstring & path); + plString GetString(const plString & path, const std::vector & args); + plString GetString(const plString & path); }; #endif diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp index 704215f7..404d94e4 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp @@ -62,13 +62,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// Constructors //////////////////////////////////////////////////// -pfLocalizedString::pfLocalizedString(const wchar_t *plainText) -{ - fNumArguments = 0; - IConvertFromPlainText(plainText); -} - -pfLocalizedString::pfLocalizedString(const std::wstring & plainText) +pfLocalizedString::pfLocalizedString(const plString & plainText) { fNumArguments = 0; IConvertFromPlainText(plainText); @@ -76,7 +70,7 @@ pfLocalizedString::pfLocalizedString(const std::wstring & plainText) //// IConvertFromPlainText /////////////////////////////////////////// -void pfLocalizedString::IConvertFromPlainText(const std::wstring & plainText) +void pfLocalizedString::IConvertFromPlainText(const plString & plainText) { textBlock curTextBlock; fText.clear(); @@ -84,22 +78,23 @@ void pfLocalizedString::IConvertFromPlainText(const std::wstring & plainText) fNumArguments = 0; // reset the argument count int curParameter = 0; - for (std::wstring::size_type curIndex = 0; curIndex < plainText.size(); curIndex++) + plString::iterator iter = plainText.GetIterator(); + while (!iter.AtEnd()) { - wchar_t curChar = plainText[curIndex]; - bool isLastChar = (curIndex == (plainText.length() - 1)); + wchar_t curChar = *iter; + bool isLastChar = iter.AtEnd(); switch (curChar) { case L'\\': if (!isLastChar) { // we need to see the next character - curIndex++; - wchar_t nextChar = plainText[curIndex]; + iter++; + wchar_t nextChar = *iter; if ((nextChar == L'%')||(nextChar == L'\\')) { // we recognize it as an escaped character, so add it to the text - curTextBlock.fText += nextChar; + curTextBlock.fText += plString::FromWchar((const wchar_t *)(nextChar)); } // otherwise we don't recognize it and it will be skipped } @@ -157,28 +152,24 @@ void pfLocalizedString::IConvertFromPlainText(const std::wstring & plainText) void pfLocalizedString::IUpdatePlainText() { - fPlainTextRep = L""; - for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) + fPlainTextRep = ""; + + for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { textBlock curTextBlock = fText[curIndex]; if (curTextBlock.fIsParam) { - std::wstring paramStr = L"%"; - wchar_t buff[256]; - swprintf(buff, 256, L"%d", curTextBlock.fParamIndex + 1); - paramStr += buff; - paramStr += L"s"; - fPlainTextRep += paramStr; + fPlainTextRep += plString::Format("%%%ds", curTextBlock.fParamIndex + 1); } else { // otherwise, we need to copy all the text over, making sure that % and \ are properly escaped - for (std::wstring::size_type curChar = 0; curChar < curTextBlock.fText.size(); curChar++) + for (plString::iterator iter = curTextBlock.fText.GetIterator(); !iter.AtEnd(); iter++) { - if ((curTextBlock.fText[curChar] == L'\\')||(curTextBlock.fText[curChar] == L'%')) - fPlainTextRep += L"\\"; - fPlainTextRep += curTextBlock.fText[curChar]; + if (((*iter) == L'\\') || ((*iter) == L'%')) + fPlainTextRep += "\\"; + fPlainTextRep += plString::FromWchar((const wchar_t *)(*iter)); } } } @@ -186,7 +177,7 @@ void pfLocalizedString::IUpdatePlainText() //// IConvertFromXML ///////////////////////////////////////////////// -void pfLocalizedString::IConvertFromXML(const std::wstring & xml) +void pfLocalizedString::IConvertFromXML(const plString & xml) { textBlock curTextBlock; fText.clear(); @@ -267,35 +258,32 @@ void pfLocalizedString::IConvertFromXML(const std::wstring & xml) void pfLocalizedString::IUpdateXML() { - fXMLRep = L""; - for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) + fXMLRep = ""; + for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { textBlock curTextBlock = fText[curIndex]; if (curTextBlock.fIsParam) { - std::wstring paramStr = L"%"; - wchar_t buff[256]; - swprintf(buff, 256, L"%d", curTextBlock.fParamIndex + 1); - paramStr += buff; - paramStr += L"s"; + plString paramStr = plString::Format("%%%ds", curTextBlock.fParamIndex + 1); fXMLRep += paramStr; } else { // otherwise, we need to copy all the text over, making sure that %, &, <, and > are properly converted - for (std::wstring::size_type curChar = 0; curChar < curTextBlock.fText.size(); curChar++) + for (plString::iterator iter = curTextBlock.fText.GetIterator(); !iter.AtEnd(); iter++) { - if (curTextBlock.fText[curChar] == L'%') - fXMLRep += L"\\%"; - else if (curTextBlock.fText[curChar] == L'&') - fXMLRep += L"&"; - else if (curTextBlock.fText[curChar] == L'<') - fXMLRep += L"<"; - else if (curTextBlock.fText[curChar] == L'>') - fXMLRep += L">"; + UniChar curChar = *iter; + if (curChar == L'%') + fXMLRep += "\\%"; + else if (curChar == L'&') + fXMLRep += "&"; + else if (curChar == L'<') + fXMLRep += "<"; + else if (curChar == L'>') + fXMLRep += ">"; else - fXMLRep += curTextBlock.fText[curChar]; + fXMLRep += plString::FromWchar((const wchar_t *)curChar); } } } @@ -303,7 +291,7 @@ void pfLocalizedString::IUpdateXML() //// FromXML ///////////////////////////////////////////////////////// -void pfLocalizedString::FromXML(const std::wstring & xml) +void pfLocalizedString::FromXML(const plString & xml) { IConvertFromXML(xml); } @@ -354,22 +342,16 @@ pfLocalizedString &pfLocalizedString::operator+=(pfLocalizedString &obj) return *this; } -pfLocalizedString &pfLocalizedString::operator=(const std::wstring & plainText) -{ - IConvertFromPlainText(plainText); - return *this; -} - -pfLocalizedString &pfLocalizedString::operator=(const wchar_t *plainText) +pfLocalizedString &pfLocalizedString::operator=(const plString & plainText) { IConvertFromPlainText(plainText); return *this; } -std::wstring pfLocalizedString::operator%(const std::vector & arguments) +plString pfLocalizedString::operator%(const std::vector & arguments) { - std::wstring retVal = L""; - for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) + plString retVal = ""; + for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { if (fText[curIndex].fIsParam) { diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h index fc5f4f3f..58350353 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h @@ -51,9 +51,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _pfLocalizedString_h #include "HeadSpin.h" +#include "plString.h" #include -#include - //// pfLocalizedString Class Definition ////////////////////////////// // a small class to handle localized strings and which can take @@ -67,30 +66,29 @@ protected: struct textBlock { bool fIsParam; // if true, then this is a parameter, not a string - std::wstring fText; - uint8_t fParamIndex; + plString fText; + uint8_t fParamIndex; textBlock() : fIsParam(false), fParamIndex(0) {} }; - std::vector fText; // the individual text elements that make up this string - std::wstring fXMLRep; // the XML representation of this string - std::wstring fPlainTextRep; // the plain text representation of this string - uint16_t fNumArguments; // number of arguments this string has + std::vector fText; // the individual text elements that make up this string + plString fXMLRep; // the XML representation of this string + plString fPlainTextRep; // the plain text representation of this string + uint16_t fNumArguments; // number of arguments this string has - void IConvertFromPlainText(const std::wstring & plainText); + void IConvertFromPlainText(const plString & plainText); void IUpdatePlainText(); // from the internal representation - void IConvertFromXML(const std::wstring & xml); + void IConvertFromXML(const plString & xml); void IUpdateXML(); // from the internal representation public: pfLocalizedString() : fNumArguments(0) {} - pfLocalizedString(const wchar_t *plainText); - pfLocalizedString(const std::wstring & plainText); + pfLocalizedString(const plString & plainText); virtual ~pfLocalizedString() {} // To translate to and from xml format (where <, > and other signs can't be used) - void FromXML(const std::wstring & xml); - std::wstring ToXML() {return fXMLRep;} + void FromXML(const plString & xml); + plString ToXML() {return fXMLRep;} uint16_t GetArgumentCount() {return fNumArguments;} @@ -103,17 +101,14 @@ public: bool operator>=(pfLocalizedString &obj); bool operator!=(pfLocalizedString &obj); - //operator const wchar_t *() {return fPlainTextRep.c_str();} - operator std::wstring() {return fPlainTextRep;} + operator plString() {return fPlainTextRep;} pfLocalizedString operator+(pfLocalizedString &obj); pfLocalizedString &operator+=(pfLocalizedString &obj); - - pfLocalizedString &operator=(const std::wstring & plainText); - pfLocalizedString &operator=(const wchar_t *plainText); + pfLocalizedString &operator=(const plString & plainText); // Specialized operator for replacing text with arguments - std::wstring operator%(const std::vector & arguments); + plString operator%(const std::vector & arguments); }; #endif From 14632eecee99e891ae6e6b471499f82cc03c6fb4 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 10 Jan 2013 08:12:02 -0800 Subject: [PATCH 2/6] Use plString in pfLocalizationMgr - Part 2 More clean-up and adjustments to use plString in pfLocalizationMgr and associated classes. --- .../pfGameGUIMgr/pfGUITextBoxMod.cpp | 2 +- .../pfLocalizationDataMgr.cpp | 126 ++++---- .../pfLocalizationMgr/pfLocalizationMgr.cpp | 4 +- .../pfLocalizationMgr/pfLocalizationMgr.h | 2 +- .../pfLocalizationMgr/pfLocalizedString.cpp | 269 ++++++------------ .../pfLocalizationMgr/pfLocalizedString.h | 1 + Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 4 +- Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 2 +- .../Plasma/FeatureLib/pfPython/cyMiscGlue.cpp | 20 +- 9 files changed, 162 insertions(+), 268 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp index e5f1f574..9aaa02dc 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp @@ -121,7 +121,7 @@ void pfGUITextBoxMod::IUpdate( void ) std::wstring drawStr; if (fUseLocalizationPath && !fLocalizationPath.IsEmpty() && pfLocalizationMgr::InstanceValid()) - drawStr = pfLocalizationMgr::Instance().GetString(fLocalizationPath.ToWchar().GetData()); + drawStr = pfLocalizationMgr::Instance().GetString(fLocalizationPath).ToWchar().GetData(); else { if( fText != nil ) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp index cf9ee052..60513871 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.cpp @@ -62,10 +62,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -// MinGW sucks -#if defined(_WIN32) && !defined(_MSC_VER) -# define swprintf _snwprintf -#endif ////////////////////////////////////////////////////////////////////// // @@ -120,11 +116,10 @@ protected: void IHandleAgeTag(const tagInfo & parentTag, const tagInfo & thisTag); void IHandleSetTag(const tagInfo & parentTag, const tagInfo & thisTag); void IHandleElementTag(const tagInfo & parentTag, const tagInfo & thisTag); - void IHandleTranslationTag(const tagInfo & parentTag, const tagInfo & thisTag); public: - LocalizationXMLFile() : fWeExploded(false), fFilename("") { } + LocalizationXMLFile() : fWeExploded(false) { } bool Parse(const plString & fileName); // returns false on failure void AddError(const plString & errorText); @@ -174,7 +169,7 @@ XML_Memory_Handling_Suite gHeapAllocator = { ////////////////////////////////////////////////////////////////////// //// XML Parsing functions /////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// -//metmet remove static + void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *element, const XML_Char **attributes) { plString wElement = plString::FromWchar(element); @@ -182,7 +177,7 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme std::map wAttributes; for (int i = 0; attributes[i]; i += 2) - wAttributes[plString::FromWchar(static_cast(attributes[i]))] = plString::FromWchar(static_cast(attributes[i+1])); + wAttributes[plString::FromWchar(attributes[i])] = plString::FromWchar(attributes[i+1]); LocalizationXMLFile::tagInfo parentTag; if (!file->fTagStack.empty()) @@ -209,9 +204,9 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme else if (wElement == "translation") file->IHandleTranslationTag(parentTag, newTag); else - file->AddError(plString::Format("Unknown tag %S found", wElement.c_str())); + file->AddError(plString::Format("Unknown tag %s found", wElement.c_str())); } -//metmet remove static and include the function inside LocalizationXMLFile + void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element) { plString wElement = plString::FromWchar(element); @@ -238,7 +233,7 @@ void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element file->fTagStack.pop(); } -//metmet remove static and include the function inside LocalizationXMLFile + void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *data, int stringLength) { LocalizationXMLFile *file = (LocalizationXMLFile*)userData; @@ -249,10 +244,10 @@ void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *dat // 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) - plString wData = plString::FromWchar(data); + plString contents = plString::FromWchar(data, stringLength); // 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] += contents; } ////////////////////////////////////////////////////////////////////// @@ -265,7 +260,7 @@ void XMLCALL LocalizationXMLFile::HandleData(void *userData, const XML_Char *dat void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) { - if (parentTag.fTag != "") // we only allow tags at root level + if (!parentTag.fTag.IsEmpty()) // we only allow tags at root level { AddError("localizations tag only allowed at root level"); return; @@ -359,7 +354,7 @@ void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagIn //// Parse() ///////////////////////////////////////////////////////// -bool LocalizationXMLFile::Parse(const plString & fileName) +bool LocalizationXMLFile::Parse(const plString& fileName) { fFilename = fileName; @@ -390,7 +385,7 @@ bool LocalizationXMLFile::Parse(const plString & fileName) hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str()); if (!xmlStream) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %S", fileName.c_str()); + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Can't open file stream for %s", fileName.c_str()); return false; } @@ -424,7 +419,7 @@ bool LocalizationXMLFile::Parse(const plString & fileName) void LocalizationXMLFile::AddError(const plString& errorText) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR (line %d): %S", + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR (line %d): %s", XML_GetCurrentLineNumber(fParser), errorText.c_str()); fSkipDepth = fTagStack.size(); // skip this block fWeExploded = true; @@ -443,7 +438,6 @@ class LocalizationDatabase { protected: plString fDirectory; // the directory we're supposed to parse - plString fErrorString; // total sum of all errors encountered (also has warnings and status messages) std::vector fFiles; // the various XML files in that directory @@ -480,7 +474,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio { if (firstElement.find(curTranslation->first) != firstElement.end()) { - pfLocalizationDataMgr::GetLog()->AddLineF("Duplicate %S translation for %S found in file %S Ignoring second translation", + 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 @@ -502,7 +496,8 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile if (firstSet.find(curElement->first) == firstSet.end()) firstSet[curElement->first] = curElement->second; else // merge the element in - firstSet[curElement->first] = IMergeElementData(firstSet[curElement->first], curElement->second, fileName, path + "." + curElement->first); + firstSet[curElement->first] = IMergeElementData(firstSet[curElement->first], curElement->second, fileName, + plString::Format("%s.%s", path.c_str(), curElement->first.c_str())); } return firstSet; @@ -520,7 +515,8 @@ LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile if (firstAge.find(curSet->first) == firstAge.end()) firstAge[curSet->first] = curSet->second; else // merge the data in - firstAge[curSet->first] = IMergeSetData(firstAge[curSet->first], curSet->second, fileName, path + "." + curSet->first); + firstAge[curSet->first] = IMergeSetData(firstAge[curSet->first], curSet->second, fileName, + plString::Format("%s.%s", path.c_str(), curSet->first.c_str())); } return firstAge; @@ -579,7 +575,7 @@ void LocalizationDatabase::IVerifyElement(const plString &ageName, const plStrin if (!languageExists) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: The language %S used by %S.%S.%S is not supported, discarding translation", + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: The language %s used by %s.%s.%s is not supported. Discarding translation.", curTranslation->first.c_str(), ageName.c_str(), setName.c_str(), elementName.c_str()); curTranslation = theElement.erase(curTranslation); } @@ -591,7 +587,7 @@ void LocalizationDatabase::IVerifyElement(const plString &ageName, const plStrin { if (theElement.find(languageNames[i]) == theElement.end()) { - pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Language %S is missing from the translations in element %S.%S.%S, you'll want to get translations for that!", + pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Language %s is missing from the translations in element %s.%s.%s. You'll want to get translations for that!", languageNames[i].c_str(), ageName.c_str(), setName.c_str(), elementName.c_str()); } } @@ -611,7 +607,7 @@ void LocalizationDatabase::IVerifySet(const plString &ageName, const plString &s // Check that we at least have a default language translation for fallback if (curElement->second.find(defaultLanguage) == curElement->second.end()) { - pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Default language %S is missing from the translations in element %S.%S.%S, deleting element", + pfLocalizationDataMgr::GetLog()->AddLineF("ERROR: Default language %s is missing from the translations in element %s.%s.%s. Deleting element.", defaultLanguage.c_str(), ageName.c_str(), setName.c_str(), curElement->first.c_str()); curElement = theSet.erase(curElement); } @@ -679,20 +675,13 @@ void LocalizationDatabase::Parse(const plString & directory) template void pfLocalizationDataMgr::pf3PartMap::ISplitString(plString key, plString &age, plString &set, plString &name) { - int periodLoc = key.Find("."); - age = key.Substr(0, periodLoc); - if (periodLoc >= key.GetSize()) { - return; // don't get set or name if there isn't any period - } - - key = key.Substr(periodLoc + 1, key.GetSize()); - periodLoc = key.Find("."); - set = key.Substr(0, periodLoc); - if (periodLoc >= key.GetSize()) { - return; // don't get name if there isn't another period - } - - name = key.Substr(periodLoc + 1, key.GetSize()); + std::vector tokens = key.Tokenize("."); + if (tokens.size() >= 1) + age = tokens[0]; + if (tokens.size() >= 2) + set = tokens[1]; + if (tokens.size() >= 3) + name = tokens[2]; } //// exists() //////////////////////////////////////////////////////// @@ -702,7 +691,7 @@ bool pfLocalizationDataMgr::pf3PartMap::exists(const plString & key) { plString age, set, name; ISplitString(key, age, set, name); - if (age == "" || set == "" || name == "") // if any are missing, it's invalid, so we don't have it + if (age.IsEmpty() || set.IsEmpty() || name.IsEmpty()) // if any are missing, it's invalid, so we don't have it return false; // now check individually @@ -724,7 +713,7 @@ bool pfLocalizationDataMgr::pf3PartMap::setExists(const plString & key) { plString age, set, name; ISplitString(key, age, set, name); - if (age == "" || set == "") // if any are missing, it's invalid, so we don't have it (ignoring name) + if (age.IsEmpty() || set.IsEmpty()) // if any are missing, it's invalid, so we don't have it (ignoring name) return false; // now check individually @@ -744,7 +733,7 @@ void pfLocalizationDataMgr::pf3PartMap::erase(const plString & key) { plString age, set, name; ISplitString(key, age, set, name); - if (age == "" || set == "" || name == "") // if any are missing, it's invalid, so we don't delete it + if (age.IsEmpty() || set.IsEmpty() || name.IsEmpty()) // if any are missing, it's invalid, so we don't delete it return; // now check individually @@ -863,8 +852,7 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE for (int curLocale = 0; curLocale <= numLocales; curLocale++) { - plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); - retVal[name] = ""; + retVal[plLocalization::GetLanguageName((plLocalization::Language)curLocale)] = ""; } return retVal; @@ -874,8 +862,7 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE plString pfLocalizationDataMgr::IGetCurrentLanguageName() { - plString retVal = plLocalization::GetLanguageName(plLocalization::GetLanguage()); - return retVal; + return plLocalization::GetLanguageName(plLocalization::GetLanguage()); } //// IGetAllLanguageNames //////////////////////////////////////////// @@ -909,7 +896,7 @@ void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const p if (numArgs == -1) // just started numArgs = argCount; else if (argCount != numArgs) - fLog->AddLineF("WARNING: Argument number mismatch in element %S for %S", curPath.c_str(), curTranslation->first.c_str()); + fLog->AddLineF("WARNING: Argument number mismatch in element %s for %s", curPath.c_str(), curTranslation->first.c_str()); } fLocalizedElements[curPath] = newElement; @@ -925,7 +912,7 @@ void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const plString & cu LocElementInfo elementInfo; elementInfo.fElement = curElement->second; - IConvertElement(&elementInfo, plString::Format("%S.%S", curPath.c_str(), curElement->first.c_str())); + IConvertElement(&elementInfo, plString::Format("%s.%s", curPath.c_str(), curElement->first.c_str())); } } @@ -939,7 +926,7 @@ void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const plString & cu LocSetInfo setInfo; setInfo.fSet = curSet->second; - IConvertSet(&setInfo, plString::Format("%S.%S", curPath.c_str(), curSet->first.c_str())); + IConvertSet(&setInfo, plString::Format("%s.%s", curPath.c_str(), curSet->first.c_str())); } } @@ -954,26 +941,26 @@ void pfLocalizationDataMgr::IWriteText(const plString & filename, const plString plStringStream fileData; fileData << "\n"; // stores the xml we are going to write to the file (UTF-16 format) fileData << "\n"; - fileData << plString::Format("\t\n", ageName.c_str()); + fileData << plString::Format("\t\n", ageName.c_str()); std::vector setNames = GetSetList(ageName); for (int curSet = 0; curSet < setNames.size(); curSet++) { setEmpty = true; // so far, this set is empty plStringStream setCode; - setCode << plString::Format("\t\t\n", setNames[curSet].c_str()); + setCode << plString::Format("\t\t\n", setNames[curSet].c_str()); std::vector elementNames = GetElementList(ageName, setNames[curSet]); for (int curElement = 0; curElement < elementNames.size(); curElement++) { - setCode << plString::Format("\t\t\t\n", elementNames[curElement].c_str()); - plString key = plString::Format("%S.%S.%S", ageName.c_str(), setNames[curSet].c_str(), elementNames[curElement].c_str()); + setCode << plString::Format("\t\t\t\n", elementNames[curElement].c_str()); + plString key = plString::Format("%s.%s.%s", ageName.c_str(), setNames[curSet].c_str(), elementNames[curElement].c_str()); if (fLocalizedElements[key].find(languageName) != fLocalizedElements[key].end()) { weWroteData = true; setEmpty = false; - setCode << plString::Format("\t\t\t\t", languageName.c_str()); + setCode << plString::Format("\t\t\t\t", languageName.c_str()); setCode << fLocalizedElements[key][languageName].ToXML(); setCode << "\n"; } @@ -1044,7 +1031,7 @@ void pfLocalizationDataMgr::SetupData() // and now we read all the data out of the database and convert it to our native formats - // transfer subtitle data + // transfer localization data LocalizationXMLFile::ageMap data = fDatabase->GetData(); LocalizationXMLFile::ageMap::iterator curAge; for (curAge = data.begin(); curAge != data.end(); curAge++) @@ -1099,7 +1086,7 @@ pfLocalizedString pfLocalizationDataMgr::GetSpecificElement(const plString & nam std::vector pfLocalizationDataMgr::GetLanguages(const plString & ageName, const plString & setName, const plString & elementName) { std::vector retVal; - plString key = plString::Format("%S.%S.%S", ageName.c_str(), setName.c_str(), elementName.c_str()); + plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str()); if (fLocalizedElements.exists(key)) { // age, set, and element exists @@ -1119,26 +1106,18 @@ std::vector pfLocalizationDataMgr::GetLanguages(const plString & ageNa plString pfLocalizationDataMgr::GetElementXMLData(const plString & name, const plString & languageName) { - plString retVal = ""; - if (fLocalizedElements.exists(name)) - { - if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) - retVal = fLocalizedElements[name][languageName].ToXML(); - } - return retVal; + if (fLocalizedElements.exists(name) && (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end())) + return fLocalizedElements[name][languageName].ToXML(); + return ""; } //// GetElementPlainTextData ///////////////////////////////////////// plString pfLocalizationDataMgr::GetElementPlainTextData(const plString & name, const plString & languageName) { - plString retVal = ""; - if (fLocalizedElements.exists(name)) - { - if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) - retVal = fLocalizedElements[name][languageName]; - } - return retVal; + if (fLocalizedElements.exists(name) && (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end())) + return fLocalizedElements[name][languageName]; + return ""; } //// SetElementXMLData /////////////////////////////////////////////// @@ -1217,14 +1196,13 @@ bool pfLocalizationDataMgr::DeleteElement(const plString & name) void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) { - // first, write the styles and panel settings to styles.sub std::vector ageNames = GetAgeList(); std::vector languageNames = IGetAllLanguageNames(); for (int curAge = 0; curAge < ageNames.size(); curAge++) { for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++) { - IWriteText(plString::Format("%S/%S%S.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]); + IWriteText(plString::Format("%s/%s%s.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]); } } } @@ -1241,19 +1219,19 @@ void pfLocalizationDataMgr::OutputTreeToLog() for (std::vector::iterator i = ages.begin(); i != ages.end(); ++i) { plString age = *i; - fLog->AddLineF("\t%S", age.c_str()); + fLog->AddLineF("\t%s", age.c_str()); std::vector sets = GetSetList(age); for (std::vector::iterator j = sets.begin(); j != sets.end(); ++j) { plString set = (*j); - fLog->AddLineF("\t\t%S", set.c_str()); + fLog->AddLineF("\t\t%s", set.c_str()); std::vector names = GetElementList(age, set); for (std::vector::iterator k = names.begin(); k != names.end(); ++k) { plString name = (*k); - fLog->AddLineF("\t\t\t%S", name.c_str()); + fLog->AddLineF("\t\t\t%s", name.c_str()); } } } diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp index 3d47e5fe..e6de8c66 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.cpp @@ -73,13 +73,13 @@ pfLocalizationMgr::~pfLocalizationMgr() //// Initialize ////////////////////////////////////////////////////// -void pfLocalizationMgr::Initialize(const std::string & dataPath) +void pfLocalizationMgr::Initialize(const plString & dataPath) { if (fInstance) return; fInstance = new pfLocalizationMgr(); - pfLocalizationDataMgr::Initialize(dataPath.c_str()); // set up the data manager + pfLocalizationDataMgr::Initialize(dataPath); // set up the data manager } //// Shutdown //////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h index e8df4234..7fc99964 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h @@ -60,7 +60,7 @@ protected: public: virtual ~pfLocalizationMgr(); - static void Initialize(const std::string & dataPath); + static void Initialize(const plString & dataPath); static void Shutdown(); static pfLocalizationMgr &Instance(void) {return *fInstance;} static bool InstanceValid(void) {return fInstance != nil;} diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp index 404d94e4..510735fe 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp @@ -51,10 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfLocalizedString.h" -// MinGW sucks -#if defined(_WIN32) && !defined(_MSC_VER) -# define swprintf _snwprintf -#endif ////////////////////////////////////////////////////////////////////// //// pfLocalizedString functions ///////////////////////////////////// @@ -63,87 +59,89 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// Constructors //////////////////////////////////////////////////// pfLocalizedString::pfLocalizedString(const plString & plainText) + : fNumArguments(0) { - fNumArguments = 0; IConvertFromPlainText(plainText); } -//// IConvertFromPlainText /////////////////////////////////////////// +//// IParameterize /////////////////////////////////////////////////// -void pfLocalizedString::IConvertFromPlainText(const plString & plainText) +void pfLocalizedString::IParameterize(const plString & inString) { textBlock curTextBlock; - fText.clear(); - fPlainTextRep = plainText; - fNumArguments = 0; // reset the argument count + fNumArguments = 0; // Reset the argument count. + fText.clear(); // Reset the text blocks. + + plString remainder = inString; + plStringStream newText; int curParameter = 0; + int nextToken = -1; - plString::iterator iter = plainText.GetIterator(); - while (!iter.AtEnd()) + while (!remainder.IsEmpty()) { - wchar_t curChar = *iter; - bool isLastChar = iter.AtEnd(); - switch (curChar) - { - case L'\\': - if (!isLastChar) - { - // we need to see the next character - iter++; - wchar_t nextChar = *iter; - if ((nextChar == L'%')||(nextChar == L'\\')) - { - // we recognize it as an escaped character, so add it to the text - curTextBlock.fText += plString::FromWchar((const wchar_t *)(nextChar)); - } - // otherwise we don't recognize it and it will be skipped - } - // if it's the last char, just drop it - break; - case L'%': - if (!isLastChar) - { - // we need to grab the trailing s character - std::wstring::size_type endArgPos = plainText.find(L"s", curIndex); - if (endArgPos != std::wstring::npos) // make sure the s exists - { - if (endArgPos == (curIndex + 1)) // no number specifier - { - fText.push_back(curTextBlock); + // Check if we have any params. + nextToken = remainder.Find("%"); + if (nextToken != -1) + { + // Check it's not escaped. + if ((nextToken > 0) && (remainder.CharAt(nextToken-1) != '\\')) + { + // Check if it has an end. + int endToken = remainder.Substr(nextToken).Find("s"); + if (endToken != -1) + { + // Store existing block. + newText << remainder; + curTextBlock.fText = newText.GetString().Replace("\\\\", "\\"); + fText.push_back(curTextBlock); + + if (endToken == nextToken + 1) + { + // Store non-indexed param block. curTextBlock.fIsParam = true; - curTextBlock.fParamIndex = curParameter; - curParameter++; - curTextBlock.fText = L""; - fText.push_back(curTextBlock); - curTextBlock.fIsParam = false; - curTextBlock.fParamIndex = 0; - } - else // number specified - { + curTextBlock.fParamIndex = curParameter++; + curTextBlock.fText = ""; fText.push_back(curTextBlock); + } + else + { + // Store indexed param block. curTextBlock.fIsParam = true; - curTextBlock.fText = L""; - - std::wstring number = plainText.substr(curIndex + 1, (endArgPos - (curIndex + 1))); - curTextBlock.fParamIndex = (uint8_t)wcstol(number.c_str(), NULL, 10) - 1; // args are 1-based, vectors are 0-based + curTextBlock.fParamIndex = remainder.Substr(nextToken, endToken-1).ToInt(10) - 1; // args start at 1 + curTextBlock.fText = ""; fText.push_back(curTextBlock); - - curTextBlock.fIsParam = false; - curTextBlock.fParamIndex = 0; - } - fNumArguments++; // increment our argument count - curIndex = endArgPos; // update our position - } - // if s didn't exist, we just skip this % sign - } - // if it was the last char, we just skip this % sign - break; - default: - curTextBlock.fText += curChar; - break; - } + } + curTextBlock.fIsParam = false; + curTextBlock.fParamIndex = 0; + fNumArguments++; + + // Continue using the remaining string. + remainder = remainder.Substr(endToken+1); + } + } + else + { + // Copy the text up to the escape character, skip it, and continue. + newText << remainder.Substr(0, nextToken - 1) << '%'; + remainder = remainder.Substr(nextToken + 1); + } + } + else + { + // We're done. Copy the remaining text and finish. + newText << remainder; + remainder = ""; + curTextBlock.fText = newText.GetString().Replace("\\\\", "\\"); + fText.push_back(curTextBlock); + } } - fText.push_back(curTextBlock); +} + +//// IConvertFromPlainText /////////////////////////////////////////// + +void pfLocalizedString::IConvertFromPlainText(const plString & plainText) +{ + IParameterize(plainText); IUpdateXML(); } @@ -152,7 +150,7 @@ void pfLocalizedString::IConvertFromPlainText(const plString & plainText) void pfLocalizedString::IUpdatePlainText() { - fPlainTextRep = ""; + plStringStream ss; for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { @@ -160,133 +158,50 @@ void pfLocalizedString::IUpdatePlainText() if (curTextBlock.fIsParam) { - fPlainTextRep += plString::Format("%%%ds", curTextBlock.fParamIndex + 1); + // Fill in parameter value. + ss << plString::Format("%%%ds", curTextBlock.fParamIndex + 1); } else { - // otherwise, we need to copy all the text over, making sure that % and \ are properly escaped - for (plString::iterator iter = curTextBlock.fText.GetIterator(); !iter.AtEnd(); iter++) - { - if (((*iter) == L'\\') || ((*iter) == L'%')) - fPlainTextRep += "\\"; - fPlainTextRep += plString::FromWchar((const wchar_t *)(*iter)); - } + // Escape special characters. + ss << curTextBlock.fText.Replace("\\","\\\\").Replace("%","\\%"); } } + fPlainTextRep = ss.GetString(); } //// IConvertFromXML ///////////////////////////////////////////////// void pfLocalizedString::IConvertFromXML(const plString & xml) { - textBlock curTextBlock; - fText.clear(); - fNumArguments = 0; // reset the argument counter - int curParameter = 0; - - for (std::wstring::size_type curIndex = 0; curIndex < xml.length(); curIndex++) - { - wchar_t curChar = xml[curIndex]; - bool isLastChar = (curIndex == (xml.length() - 1)); - switch (curChar) - { // expat handles the > < and so on stuff for us - case L'\\': // but we want to be able to escape the % sign and the \ character - if (!isLastChar) - { - // we need to see the next character - curIndex++; - wchar_t nextChar = xml[curIndex]; - if ((nextChar == L'%')||(nextChar == L'\\')) - { - // we recognize it as an escaped character, so add it to the text - curTextBlock.fText += nextChar; - } - // otherwise we don't recognize it and it will be skipped - } - // if it's the last char, just drop it - break; - case L'%': - if (!isLastChar) - { - // we need to grab the trailing s character - std::wstring::size_type endArgPos = xml.find(L"s", curIndex); - if (endArgPos != std::wstring::npos) // make sure the s exists - { - if (endArgPos == (curIndex + 1)) // no number specifier - { - fText.push_back(curTextBlock); - curTextBlock.fIsParam = true; - curTextBlock.fParamIndex = curParameter; - curParameter++; - curTextBlock.fText = L""; - fText.push_back(curTextBlock); - curTextBlock.fIsParam = false; - curTextBlock.fParamIndex = 0; - } - else // number specified - { - fText.push_back(curTextBlock); - curTextBlock.fIsParam = true; - curTextBlock.fText = L""; - - std::wstring number = xml.substr(curIndex + 1, (endArgPos - (curIndex + 1))); - curTextBlock.fParamIndex = (uint8_t)wcstol(number.c_str(), nil, 10) - 1; // args are 1-based, vectors are 0-based - fText.push_back(curTextBlock); - - curTextBlock.fIsParam = false; - curTextBlock.fParamIndex = 0; - } - fNumArguments++; // increment the number of arguments - curIndex = endArgPos; // update our position - } - // if s didn't exist, we just skip this % sign - } - // if it was the last char, we just skip this % sign - break; - default: - curTextBlock.fText += curChar; - break; - } - } - fText.push_back(curTextBlock); + IParameterize(xml); IUpdatePlainText(); - IUpdateXML(); // we don't really get pure xml from the parser (since it auto translates all the &x; stuff) + IUpdateXML(); } //// IUpdateXML ////////////////////////////////////////////////////// void pfLocalizedString::IUpdateXML() { - fXMLRep = ""; + plStringStream ss; for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { textBlock curTextBlock = fText[curIndex]; if (curTextBlock.fIsParam) { + // Fill in parameter value. plString paramStr = plString::Format("%%%ds", curTextBlock.fParamIndex + 1); - fXMLRep += paramStr; + ss << paramStr; } else { - // otherwise, we need to copy all the text over, making sure that %, &, <, and > are properly converted - for (plString::iterator iter = curTextBlock.fText.GetIterator(); !iter.AtEnd(); iter++) - { - UniChar curChar = *iter; - if (curChar == L'%') - fXMLRep += "\\%"; - else if (curChar == L'&') - fXMLRep += "&"; - else if (curChar == L'<') - fXMLRep += "<"; - else if (curChar == L'>') - fXMLRep += ">"; - else - fXMLRep += plString::FromWchar((const wchar_t *)curChar); - } + // Encode XML entities. + ss << curTextBlock.fText.Replace("%", "\\%").Replace("&", "&").Replace("<", "<").Replace(">", ">"); } } + fXMLRep = ss.GetString(); } //// FromXML ///////////////////////////////////////////////////////// @@ -300,32 +215,32 @@ void pfLocalizedString::FromXML(const plString & xml) bool pfLocalizedString::operator<(pfLocalizedString &obj) { - return (fPlainTextRep < obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) < 0); } bool pfLocalizedString::operator>(pfLocalizedString &obj) { - return (fPlainTextRep > obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) > 0); } bool pfLocalizedString::operator==(pfLocalizedString &obj) { - return (fPlainTextRep == obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) == 0); } bool pfLocalizedString::operator<=(pfLocalizedString &obj) { - return (fPlainTextRep <= obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) <= 0); } bool pfLocalizedString::operator>=(pfLocalizedString &obj) { - return (fPlainTextRep >= obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) >= 0); } bool pfLocalizedString::operator!=(pfLocalizedString &obj) { - return (fPlainTextRep != obj.fPlainTextRep); + return (fPlainTextRep.Compare(obj.fPlainTextRep) != 0); } pfLocalizedString pfLocalizedString::operator+(pfLocalizedString &obj) @@ -350,17 +265,17 @@ pfLocalizedString &pfLocalizedString::operator=(const plString & plainText) plString pfLocalizedString::operator%(const std::vector & arguments) { - plString retVal = ""; + plStringStream ss; for (std::vector::size_type curIndex = 0; curIndex < fText.size(); curIndex++) { if (fText[curIndex].fIsParam) { int curParam = fText[curIndex].fParamIndex; if (curParam < arguments.size()) - retVal += arguments[curParam]; + ss << arguments[curParam]; } else - retVal += fText[curIndex].fText; + ss << fText[curIndex].fText; } - return retVal; + return ss.GetString(); } diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h index 58350353..e8737e7f 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h @@ -77,6 +77,7 @@ protected: plString fPlainTextRep; // the plain text representation of this string uint16_t fNumArguments; // number of arguments this string has + void IParameterize(const plString & inString); void IConvertFromPlainText(const plString & plainText); void IUpdatePlainText(); // from the internal representation void IConvertFromXML(const plString & xml); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index ad39bd78..763aab23 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -2725,11 +2725,11 @@ void cyMisc::ForceCursorShown() // properly replaced (the list is a list of unicode strings) Name // is in "Age.Set.Name" format // -std::wstring cyMisc::GetLocalizedString(std::wstring name, const std::vector & arguments) +plString cyMisc::GetLocalizedString(plString name, const std::vector & arguments) { if (pfLocalizationMgr::InstanceValid()) return pfLocalizationMgr::Instance().GetString(name, arguments); - return L""; + return ""; } void cyMisc::EnablePlanarReflections(bool enable) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index a0d901f8..0b0d8454 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -922,7 +922,7 @@ public: // properly replaced (the list is a list of unicode strings) Name // is in "Age.Set.Name" format // - static std::wstring GetLocalizedString(std::wstring name, const std::vector & arguments); + static plString GetLocalizedString(plString name, const std::vector & arguments); static void EnablePlanarReflections(bool enable = true); static void SetGraphicsOptions(int Width, int Height, int ColorDepth, bool Windowed, int NumAASamples, int MaxAnisotropicSamples, bool VSync); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index 94a75835..d512c676 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -409,8 +409,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum PyErr_SetString(PyExc_TypeError, "PtGetLocalizedString expects a unicode string and a list of unicode strings"); PYTHON_RETURN_ERROR; } - std::wstring name; - std::vector argList; + plString name; + std::vector argList; // convert name from a string or unicode string if (PyUnicode_Check(nameObj)) @@ -419,14 +419,14 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum wchar_t* buffer = new wchar_t[len + 1]; PyUnicode_AsWideChar((PyUnicodeObject*)nameObj, buffer, len); buffer[len] = L'\0'; - name = buffer; + name = plString::FromWchar(buffer); delete [] buffer; } else if (PyString_Check(nameObj)) { char* temp = PyString_AsString(nameObj); wchar_t* wTemp = hsStringToWString(temp); - name = wTemp; + name = plString::FromWchar(wTemp); delete [] wTemp; } else @@ -448,23 +448,23 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum for (int curItem = 0; curItem < len; curItem++) { PyObject* item = PyList_GetItem(argObj, curItem); - std::wstring arg = L"INVALID ARG"; + plString arg = "INVALID ARG"; if (item == Py_None) // none is allowed, but treated as a blank string - arg = L""; + arg = ""; else if (PyUnicode_Check(item)) { int strLen = PyUnicode_GetSize(item); wchar_t* buffer = new wchar_t[strLen + 1]; PyUnicode_AsWideChar((PyUnicodeObject*)item, buffer, strLen); buffer[strLen] = L'\0'; - arg = buffer; + arg = plString::FromWchar(buffer); delete [] buffer; } else if (PyString_Check(item)) { char* temp = PyString_AsString(item); wchar_t* wTemp = hsStringToWString(temp); - arg = wTemp; + arg = plString::FromWchar(wTemp); delete [] wTemp; } // everything else won't throw an error, but will show up as INVALID ARG in the string @@ -472,8 +472,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum } } - std::wstring retVal = cyMisc::GetLocalizedString(name, argList); - return PyUnicode_FromWideChar(retVal.c_str(), retVal.length()); + plString retVal = cyMisc::GetLocalizedString(name, argList); + return PyUnicode_FromWideChar(retVal.ToWchar(), retVal.GetSize()); } PYTHON_GLOBAL_METHOD_DEFINITION(PtDumpLogs, args, "Params: folder\nDumps all current log files to the specified folder (a sub-folder to the log folder)") From fc94e6bee94a5ff05f0a47174115d35e39377266 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 10 Jan 2013 08:46:23 -0800 Subject: [PATCH 3/6] Convert plLocalizationEditor to use plString. Required to match previous commits to pfLocalizationMgr and retain functionality. --- .../Tools/plLocalizationEditor/plAddDlgs.cpp | 52 +++---- .../Tools/plLocalizationEditor/plAddDlgs.h | 14 +- .../Tools/plLocalizationEditor/plEditDlg.cpp | 130 +++++++----------- .../Tools/plLocalizationEditor/plEditDlg.h | 7 +- .../plLocalizationEditor/plLocTreeView.cpp | 52 +++---- .../plLocalizationEditor/plLocTreeView.h | 8 +- .../plLocalizationEditor.cpp | 4 +- 7 files changed, 123 insertions(+), 144 deletions(-) diff --git a/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp b/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp index 4e142c83..eef4eebe 100644 --- a/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp +++ b/Sources/Tools/plLocalizationEditor/plAddDlgs.cpp @@ -151,7 +151,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); - pthis->fAgeName = buff; + pthis->fAgeName = plString::FromWchar(buff); pthis->fAgeChanged = true; pthis->IUpdateDlg(hDlg); } @@ -160,7 +160,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR wchar_t buff[256]; GetDlgItemTextW(hDlg, IDC_PARENTAGE, buff, 256); - pthis->fAgeName = buff; + pthis->fAgeName = plString::FromWchar(buff); pthis->fAgeChanged = true; pthis->IUpdateDlg(hDlg, false); } @@ -171,7 +171,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); - pthis->fSetName = buff; + pthis->fSetName = plString::FromWchar(buff); pthis->IUpdateDlg(hDlg); } else if (HIWORD(wParam) == CBN_EDITCHANGE && LOWORD(wParam) == IDC_PARENTSET) @@ -179,14 +179,14 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR wchar_t buff[256]; GetDlgItemTextW(hDlg, IDC_PARENTSET, buff, 256); - pthis->fSetName = buff; + pthis->fSetName = plString::FromWchar(buff); pthis->IUpdateDlg(hDlg, false); } else if (HIWORD(wParam) == EN_UPDATE && LOWORD(wParam) == IDC_ELEMENTNAME) { wchar_t buff[256]; GetDlgItemTextW(hDlg, IDC_ELEMENTNAME, buff, 256); - pthis->fElementName = buff; + pthis->fElementName = plString::FromWchar(buff); pthis->IUpdateDlg(hDlg); } @@ -207,7 +207,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR bool plAddElementDlg::IInitDlg(HWND hDlg) { HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTAGE); - std::vector ageNames = pfLocalizationDataMgr::Instance().GetAgeList(); + std::vector ageNames = pfLocalizationDataMgr::Instance().GetAgeList(); // add the age names to the list for (int i = 0; i < ageNames.size(); i++) @@ -229,15 +229,15 @@ bool plAddElementDlg::IInitDlg(HWND hDlg) void plAddElementDlg::IUpdateDlg(HWND hDlg, bool setFocus) { - std::wstring pathStr = L"Path: " + fAgeName + L"." + fSetName + L"." + fElementName; - SetDlgItemTextW(hDlg, IDC_PATH, pathStr.c_str()); + plString pathStr = plString::Format("Path: %s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str()); + SetDlgItemTextW(hDlg, IDC_PATH, pathStr.ToWchar()); if (fAgeChanged) // we only update this if the age changed (saves time and prevents weird bugs, like typing backwards) { // now add the sets HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTSET); SendMessage(listCtrl, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); - std::vector setNames = pfLocalizationDataMgr::Instance().GetSetList(fAgeName); + std::vector setNames = pfLocalizationDataMgr::Instance().GetSetList(fAgeName); // add the set names to the list for (int i = 0; i < setNames.size(); i++) @@ -246,24 +246,24 @@ void plAddElementDlg::IUpdateDlg(HWND hDlg, bool setFocus) // select the set we currently have int ret = (int)SendMessage(listCtrl, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)fSetName.c_str()); if (ret == CB_ERR) // couldn't find the string, so just set it as the current string in the edit box - SetDlgItemTextW(hDlg, IDC_PARENTSET, fSetName.c_str()); + SetDlgItemTextW(hDlg, IDC_PARENTSET, fSetName.ToWchar()); fAgeChanged = false; } - if (fSetName != L"" && setFocus) + if (!fSetName.IsEmpty() && setFocus) SetFocus(GetDlgItem(hDlg, IDC_ELEMENTNAME)); - if (fSetName != L"" && fElementName != L"") + if (!fSetName.IsEmpty() && fElementName.IsEmpty()) EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); else EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); } -plAddElementDlg::plAddElementDlg(std::wstring parentPath) +plAddElementDlg::plAddElementDlg(plString parentPath) { // throw away vars - std::wstring element, lang; + plString element, lang; SplitLocalizationPath(parentPath, fAgeName, fSetName, element, lang); } @@ -309,7 +309,7 @@ BOOL CALLBACK plAddLocalizationDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, int index = (int)SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); - pthis->fLanguageName = buff; + pthis->fLanguageName = plString::FromWchar(buff); pthis->IUpdateDlg(hDlg); } break; @@ -326,16 +326,16 @@ BOOL CALLBACK plAddLocalizationDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, return FALSE; } -std::vector IGetAllLanguageNames() +std::vector IGetAllLanguageNames() { int numLocales = plLocalization::GetNumLocales(); - std::vector retVal; + std::vector retVal; for (int curLocale = 0; curLocale <= numLocales; curLocale++) { const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); wchar_t *wName = hsStringToWString(name); - retVal.push_back(wName); + retVal.push_back(plString::FromWchar(wName)); delete [] wName; } @@ -344,13 +344,13 @@ std::vector IGetAllLanguageNames() bool plAddLocalizationDlg::IInitDlg(HWND hDlg) { - std::wstring pathStr = L"Path: " + fAgeName + L"." + fSetName + L"." + fElementName; - SetDlgItemTextW(hDlg, IDC_PATH, pathStr.c_str()); + plString pathStr = plString::Format("Path: %s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str()); + SetDlgItemTextW(hDlg, IDC_PATH, pathStr.ToWchar()); - std::vector existingLanguages; + std::vector existingLanguages; existingLanguages = pfLocalizationDataMgr::Instance().GetLanguages(fAgeName, fSetName, fElementName); - std::vector missingLanguages = IGetAllLanguageNames(); + std::vector missingLanguages = IGetAllLanguageNames(); for (int i = 0; i < existingLanguages.size(); i++) // remove all languages we already have { for (int j = 0; j < missingLanguages.size(); j++) @@ -382,7 +382,7 @@ bool plAddLocalizationDlg::IInitDlg(HWND hDlg) // and put it's value into the internal variable wchar_t buff[256]; GetDlgItemText(hDlg, IDC_LANGUAGE, buff, 256); - fLanguageName = buff; + fLanguageName = plString::FromWchar(buff); IUpdateDlg(hDlg); return true; @@ -390,16 +390,16 @@ bool plAddLocalizationDlg::IInitDlg(HWND hDlg) void plAddLocalizationDlg::IUpdateDlg(HWND hDlg) { - if (fLanguageName != L"") + if (!fLanguageName.IsEmpty()) EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); else EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); } -plAddLocalizationDlg::plAddLocalizationDlg(std::wstring parentPath) +plAddLocalizationDlg::plAddLocalizationDlg(plString parentPath) { // throw away vars - std::wstring lang; + plString lang; SplitLocalizationPath(parentPath, fAgeName, fSetName, fElementName, lang); } diff --git a/Sources/Tools/plLocalizationEditor/plAddDlgs.h b/Sources/Tools/plLocalizationEditor/plAddDlgs.h index 96147057..78a1481f 100644 --- a/Sources/Tools/plLocalizationEditor/plAddDlgs.h +++ b/Sources/Tools/plLocalizationEditor/plAddDlgs.h @@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsWindows.h" -#include +#include "plString.h" class plAddElementDlg { @@ -55,13 +55,13 @@ protected: bool IInitDlg(HWND hDlg); void IUpdateDlg(HWND hDlg, bool setFocus = true); - std::wstring fAgeName, fSetName, fElementName; + plString fAgeName, fSetName, fElementName; bool fAgeChanged; public: - plAddElementDlg(std::wstring parentPath); + plAddElementDlg(plString parentPath); bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise. - std::wstring GetValue() {return fAgeName + L"." + fSetName + L"." + fElementName;} + plString GetValue() {return plString::Format("%s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str());} }; class plAddLocalizationDlg @@ -72,12 +72,12 @@ protected: bool IInitDlg(HWND hDlg); void IUpdateDlg(HWND hDlg); - std::wstring fAgeName, fSetName, fElementName, fLanguageName; + plString fAgeName, fSetName, fElementName, fLanguageName; public: - plAddLocalizationDlg(std::wstring parentPath); + plAddLocalizationDlg(plString parentPath); bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise. - std::wstring GetValue() {return fLanguageName;} + plString GetValue() {return fLanguageName;} }; #endif diff --git a/Sources/Tools/plLocalizationEditor/plEditDlg.cpp b/Sources/Tools/plLocalizationEditor/plEditDlg.cpp index 61b08e5d..15661dc2 100644 --- a/Sources/Tools/plLocalizationEditor/plEditDlg.cpp +++ b/Sources/Tools/plLocalizationEditor/plEditDlg.cpp @@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plLocTreeView.h" #include "plAddDlgs.h" - #include "pfLocalizationMgr/pfLocalizationDataMgr.h" #include @@ -55,64 +54,40 @@ extern HINSTANCE gInstance; extern HWND gTreeView; // global data for this dialog -std::wstring gCurrentPath = L""; +plString gCurrentPath; // split a subtitle path up into its component parts -void SplitLocalizationPath(std::wstring path, std::wstring &ageName, std::wstring &setName, std::wstring &locName, std::wstring &locLanguage) +void SplitLocalizationPath(plString path, plString &ageName, plString &setName, plString &locName, plString &locLanguage) { - ageName = setName = locName = locLanguage = L""; - - std::wstring::size_type lastPos = 0, curPos = 0; - // separate the age name out - curPos = path.find(L"."); - if (curPos == std::wstring::npos) - { - ageName = path; - return; - } - ageName = path.substr(0, curPos); - path = path.substr(curPos + 1, path.length()); - - // separate the set name out - curPos = path.find(L"."); - if (curPos == std::wstring::npos) - { - setName = path; - return; - } - setName = path.substr(0, curPos); - path = path.substr(curPos + 1, path.length()); - - // separate the element out - curPos = path.find(L"."); - if (curPos == std::wstring::npos) - { - locName = path; - return; - } - locName = path.substr(0, curPos); - path = path.substr(curPos + 1, path.length()); - - // what's left is the language - locLanguage = path; + ageName = setName = locName = locLanguage = ""; + + std::vector tokens = path.Tokenize("."); + if (tokens.size() >= 1) + ageName = tokens[0]; + if (tokens.size() >= 2) + setName = tokens[1]; + if (tokens.size() >= 3) + locName = tokens[2]; + if (tokens.size() >= 4) + locLanguage = tokens[3]; } // saves the current localization text to the data manager void SaveLocalizationText() { - if (gCurrentPath == L"") + if (gCurrentPath.IsEmpty()) return; // no path to save uint32_t textLen = (uint32_t)SendMessage(GetDlgItem(gEditDlg, IDC_LOCALIZATIONTEXT), WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0); wchar_t *buffer = new wchar_t[textLen + 2]; GetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, buffer, textLen + 1); buffer[textLen + 1] = 0; - std::wstring plainTextData = buffer; + plString plainTextData = plString::FromWchar(buffer); delete [] buffer; - std::wstring ageName, setName, elementName, elementLanguage; + plString ageName, setName, elementName, elementLanguage; SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); - std::wstring name = ageName + L"." + setName + L"." + elementName; + plString name = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str()); pfLocalizationDataMgr::Instance().SetElementPlainTextData(name, elementLanguage, plainTextData); } @@ -132,38 +107,37 @@ void EnableDlg(BOOL enable) } // updates the edit dialog based on the path specified -void UpdateEditDlg(std::wstring locPath) +void UpdateEditDlg(plString locPath) { if (locPath == gCurrentPath) return; gCurrentPath = locPath; - std::wstring itemText = L"Text ("; - itemText += locPath + L"):"; - SetDlgItemTextW(gEditDlg, IDC_LOCPATH, itemText.c_str()); + plString itemText = plString::Format("Text (%s):", locPath.c_str()); + SetDlgItemTextW(gEditDlg, IDC_LOCPATH, itemText.ToWchar()); - std::wstring ageName = L"", setName = L"", elementName = L"", elementLanguage = L""; + plString ageName, setName, elementName, elementLanguage; SplitLocalizationPath(locPath, ageName, setName, elementName, elementLanguage); // now make sure they've drilled down deep enough to enable the dialog - if (elementLanguage == L"") // not deep enough + if (elementLanguage.IsEmpty()) // not deep enough EnableDlg(FALSE); else { EnableDlg(TRUE); - std::wstring key = ageName + L"." + setName + L"." + elementName; - std::wstring elementText = pfLocalizationDataMgr::Instance().GetElementPlainTextData(key, elementLanguage); - SetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, elementText.c_str()); + plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str()); + plString elementText = pfLocalizationDataMgr::Instance().GetElementPlainTextData(key, elementLanguage); + SetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, elementText.ToWchar()); } // now to setup the add/delete buttons - if (elementLanguage != L"") // they have selected a language + if (!elementLanguage.IsEmpty()) // they have selected a language { SetDlgItemText(gEditDlg, IDC_ADD, L"Add Localization"); EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE); SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Localization"); - if (elementLanguage != L"English") // don't allow them to delete the default language + if (elementLanguage != "English") // don't allow them to delete the default language EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE); else EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), FALSE); @@ -173,9 +147,9 @@ void UpdateEditDlg(std::wstring locPath) SetDlgItemText(gEditDlg, IDC_ADD, L"Add Element"); EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE); SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Element"); - if (elementName != L"") // the have selected an individual element + if (!elementName.IsEmpty()) // they have selected an individual element { - std::vector elementNames = pfLocalizationDataMgr::Instance().GetElementList(ageName, setName); + std::vector elementNames = pfLocalizationDataMgr::Instance().GetElementList(ageName, setName); if (elementNames.size() > 1) // they can't delete the only subtitle in a set EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE); else @@ -201,43 +175,43 @@ BOOL HandleCommandMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { SaveLocalizationText(); // save any current changes to the database - std::wstring buttonText; + plString buttonText; wchar_t buff[256]; GetDlgItemText(gEditDlg, IDC_ADD, buff, 256); - buttonText = buff; + buttonText = plString::FromWchar(buff); - if (buttonText == L"Add Element") + if (buttonText == "Add Element") { plAddElementDlg dlg(gCurrentPath); if (dlg.DoPick(gEditDlg)) { - std::wstring path = dlg.GetValue(); // path is age.set.name + plString path = dlg.GetValue(); // path is age.set.name if (!pfLocalizationDataMgr::Instance().AddElement(path)) MessageBox(gEditDlg, L"Couldn't add new element because one already exists with that name!", L"Error", MB_ICONERROR | MB_OK); else { - gCurrentPath = L""; + gCurrentPath = ""; plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::FillTreeViewFromData(gTreeView, path); UpdateEditDlg(path); } } } - else if (buttonText == L"Add Localization") + else if (buttonText == "Add Localization") { plAddLocalizationDlg dlg(gCurrentPath); if (dlg.DoPick(gEditDlg)) { - std::wstring newLanguage = dlg.GetValue(); - std::wstring ageName, setName, elementName, elementLanguage; + plString newLanguage = dlg.GetValue(); + plString ageName, setName, elementName, elementLanguage; SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); - std::wstring key = ageName + L"." + setName + L"." + elementName; + plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str()); if (!pfLocalizationDataMgr::Instance().AddLocalization(key, newLanguage)) MessageBox(gEditDlg, L"Couldn't add additional localization!", L"Error", MB_ICONERROR | MB_OK); else { - std::wstring path = key + L"." + newLanguage; // select the new language - gCurrentPath = L""; + plString path = plString::Format("%s.%s", key.c_str(), newLanguage.c_str()); + gCurrentPath = ""; plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::FillTreeViewFromData(gTreeView, path); UpdateEditDlg(path); @@ -250,39 +224,39 @@ BOOL HandleCommandMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { SaveLocalizationText(); // save any current changes to the database - std::wstring messageText = L"Are you sure that you want to delete " + gCurrentPath + L"?"; - int res = MessageBoxW(gEditDlg, messageText.c_str(), L"Delete", MB_ICONQUESTION | MB_YESNO); + plString messageText = plString::Format("Are you sure that you want to delete %s?", gCurrentPath.c_str()); + int res = MessageBoxW(gEditDlg, messageText.ToWchar(), L"Delete", MB_ICONQUESTION | MB_YESNO); if (res == IDYES) { - std::wstring buttonText; + plString buttonText; wchar_t buff[256]; GetDlgItemText(gEditDlg, IDC_DELETE, buff, 256); - buttonText = buff; + buttonText = plString::FromWchar(buff); - if (buttonText == L"Delete Element") + if (buttonText == "Delete Element") { if (!pfLocalizationDataMgr::Instance().DeleteElement(gCurrentPath)) MessageBox(gEditDlg, L"Couldn't delete element!", L"Error", MB_ICONERROR | MB_OK); else { - std::wstring path = gCurrentPath; - gCurrentPath = L""; + plString path = gCurrentPath; + gCurrentPath = ""; plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::FillTreeViewFromData(gTreeView, path); UpdateEditDlg(path); } } - else if (buttonText == L"Delete Localization") + else if (buttonText == "Delete Localization") { - std::wstring ageName, setName, elementName, elementLanguage; + plString ageName, setName, elementName, elementLanguage; SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); - std::wstring key = ageName + L"." + setName + L"." + elementName; + plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str()); if (!pfLocalizationDataMgr::Instance().DeleteLocalization(key, elementLanguage)) MessageBox(gEditDlg, L"Couldn't delete localization!", L"Error", MB_ICONERROR | MB_OK); else { - std::wstring path = gCurrentPath; - gCurrentPath = L""; + plString path = gCurrentPath; + gCurrentPath = ""; plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::FillTreeViewFromData(gTreeView, path); UpdateEditDlg(path); diff --git a/Sources/Tools/plLocalizationEditor/plEditDlg.h b/Sources/Tools/plLocalizationEditor/plEditDlg.h index d6ab43b4..b521c44d 100644 --- a/Sources/Tools/plLocalizationEditor/plEditDlg.h +++ b/Sources/Tools/plLocalizationEditor/plEditDlg.h @@ -45,7 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsWindows.h" -#include + +class plString; // Little trick to show a wait cursor while something is working class plWaitCursor @@ -63,9 +64,9 @@ public: } }; -void SplitLocalizationPath(std::wstring path, std::wstring &ageName, std::wstring &setName, std::wstring &locName, std::wstring &locLanguage); +void SplitLocalizationPath(plString path, plString &ageName, plString &setName, plString &locName, plString &locLanguage); void SaveLocalizationText(); -void UpdateEditDlg(std::wstring subtitlePath); +void UpdateEditDlg(plString subtitlePath); BOOL CALLBACK EditDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif diff --git a/Sources/Tools/plLocalizationEditor/plLocTreeView.cpp b/Sources/Tools/plLocalizationEditor/plLocTreeView.cpp index 0bb55e71..f6e5b1fd 100644 --- a/Sources/Tools/plLocalizationEditor/plLocTreeView.cpp +++ b/Sources/Tools/plLocalizationEditor/plLocTreeView.cpp @@ -48,22 +48,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "res\resource.h" #include -#include - +#include #include "pfLocalizationMgr/pfLocalizationDataMgr.h" extern HINSTANCE gInstance; -std::wstring plLocTreeView::fPath = L""; +plString plLocTreeView::fPath = ""; -HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, std::wstring text, bool sort = true) +HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, plString text, bool sort = true) { + // Semi-hack to keep these around as Win32 expects + static std::list> bufs; + plStringBuffer buf = text.ToWchar(); + bufs.push_back(buf); + TVITEM tvi = {0}; - tvi.mask = TVIF_TEXT | TVIF_PARAM; - tvi.pszText = (wchar_t*)text.c_str(); - tvi.cchTextMax = (int)text.length(); - tvi.lParam = NULL; + tvi.mask = TVIF_TEXT | TVIF_PARAM; + tvi.pszText = const_cast(buf.GetData()); + tvi.cchTextMax = static_cast(text.GetSize()); + tvi.lParam = NULL; TVINSERTSTRUCT tvins = {0}; tvins.item = tvi; @@ -76,15 +80,15 @@ HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, std::wstring text, bool sort = return TreeView_InsertItem(hTree, &tvins); } -void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPath) +void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, plString selectionPath) { - std::wstring targetAge, targetSet, targetElement, targetLang; + plString targetAge, targetSet, targetElement, targetLang; SplitLocalizationPath(selectionPath, targetAge, targetSet, targetElement, targetLang); bool ageMatched = false; bool setMatched = false; bool elementMatched = false; - std::vector ages = pfLocalizationDataMgr::Instance().GetAgeList(); + std::vector ages = pfLocalizationDataMgr::Instance().GetAgeList(); for (int curAge = 0; curAge < ages.size(); curAge++) { // add the age to the tree @@ -99,10 +103,10 @@ void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPa else ageMatched = false; - std::vector sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]); + std::vector sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]); for (int curSet = 0; curSet < sets.size(); curSet++) { - std::vector elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]); + std::vector elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]); HTREEITEM setItem = AddLeaf(treeCtrl, ageItem, sets[curSet]); @@ -125,13 +129,13 @@ void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPa TreeView_EnsureVisible(treeCtrl, subItem); elementMatched = true; - if (targetLang.empty()) - targetLang = L"English"; + if (targetLang.IsEmpty()) + targetLang = "English"; } else elementMatched = false; - std::vector languages = pfLocalizationDataMgr::Instance().GetLanguages(ages[curAge], sets[curSet], elements[curElement]); + std::vector languages = pfLocalizationDataMgr::Instance().GetLanguages(ages[curAge], sets[curSet], elements[curElement]); for (int curLang = 0; curLang < languages.size(); curLang++) { HTREEITEM langItem = AddLeaf(treeCtrl, subItem, languages[curLang]); @@ -155,8 +159,8 @@ void plLocTreeView::ClearTreeView(HWND treeCtrl) void plLocTreeView::SelectionChanged(HWND treeCtrl) { HTREEITEM hItem = TreeView_GetSelection(treeCtrl); - std::vector path; - fPath = L""; + std::vector path; + fPath = ""; while (hItem) { @@ -167,7 +171,7 @@ void plLocTreeView::SelectionChanged(HWND treeCtrl) tvi.pszText = s; tvi.cchTextMax = 200; TreeView_GetItem(treeCtrl, &tvi); - path.push_back(tvi.pszText); + path.push_back(plString::FromWchar(tvi.pszText)); hItem = TreeView_GetParent(treeCtrl, hItem); } @@ -177,15 +181,15 @@ void plLocTreeView::SelectionChanged(HWND treeCtrl) path.pop_back(); if (!path.empty()) - fPath += L"."; + fPath += "."; } } void plLocTreeView::SelectionDblClicked(HWND treeCtrl) { HTREEITEM hItem = TreeView_GetSelection(treeCtrl); - std::vector path; - fPath = L""; + std::vector path; + fPath = ""; while (hItem) { @@ -196,7 +200,7 @@ void plLocTreeView::SelectionDblClicked(HWND treeCtrl) tvi.pszText = s; tvi.cchTextMax = 200; TreeView_GetItem(treeCtrl, &tvi); - path.push_back(tvi.pszText); + path.push_back(plString::FromWchar(tvi.pszText)); hItem = TreeView_GetParent(treeCtrl, hItem); } @@ -206,6 +210,6 @@ void plLocTreeView::SelectionDblClicked(HWND treeCtrl) path.pop_back(); if (!path.empty()) - fPath += L"."; + fPath += "."; } } diff --git a/Sources/Tools/plLocalizationEditor/plLocTreeView.h b/Sources/Tools/plLocalizationEditor/plLocTreeView.h index 7836f79a..4a340cc8 100644 --- a/Sources/Tools/plLocalizationEditor/plLocTreeView.h +++ b/Sources/Tools/plLocalizationEditor/plLocTreeView.h @@ -43,21 +43,21 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _plLocTreeView_h #include "HeadSpin.h" -#include +#include "plString.h" class plLocTreeView { protected: - static std::wstring fPath; + static plString fPath; public: - static void FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPath); + static void FillTreeViewFromData(HWND treeCtrl, plString selectionPath); static void ClearTreeView(HWND treeCtrl); static void SelectionChanged(HWND treeCtrl); static void SelectionDblClicked(HWND treeCtrl); - static std::wstring GetPath() {return fPath;} + static plString GetPath() {return fPath;} }; #endif //_plLocTreeView_h diff --git a/Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp b/Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp index f819a44f..8f31009f 100644 --- a/Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp +++ b/Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp @@ -223,7 +223,7 @@ LRESULT CALLBACK HandleCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) bInfo.pidlRoot = NULL; bInfo.pszDisplayName = path; bInfo.lpszTitle = L"Select a localization data directory:"; - bInfo.ulFlags = BIF_EDITBOX; + bInfo.ulFlags = BIF_USENEWUI | BIF_VALIDATE | BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON; itemList = SHBrowseForFolder(&bInfo); if (itemList != NULL) @@ -242,7 +242,7 @@ LRESULT CALLBACK HandleCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) delete [] sPath; plLocTreeView::ClearTreeView(gTreeView); - plLocTreeView::FillTreeViewFromData(gTreeView, L""); + plLocTreeView::FillTreeViewFromData(gTreeView, ""); gCurPath = path; SetWindowTitle(hWnd, path); From a2dd2f60d27b1ff20f99576cafdf519fda2c3bc1 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Fri, 11 Jan 2013 10:22:41 -0800 Subject: [PATCH 4/6] Condense string conversion in Python glue. Adds fixes from code review. --- .../Plasma/FeatureLib/pfPython/cyMiscGlue.cpp | 41 +++---------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index d512c676..923ffc91 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -412,24 +412,9 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum plString name; std::vector argList; - // convert name from a string or unicode string - if (PyUnicode_Check(nameObj)) - { - int len = PyUnicode_GetSize(nameObj); - wchar_t* buffer = new wchar_t[len + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)nameObj, buffer, len); - buffer[len] = L'\0'; - name = plString::FromWchar(buffer); - delete [] buffer; - } - else if (PyString_Check(nameObj)) - { - char* temp = PyString_AsString(nameObj); - wchar_t* wTemp = hsStringToWString(temp); - name = plString::FromWchar(wTemp); - delete [] wTemp; - } - else + // convert name from a string + name = PyString_AsStringEx(nameObj); + if (name.IsNull()) { PyErr_SetString(PyExc_TypeError, "PtGetLocalizedString expects a unicode string and a list of unicode strings"); PYTHON_RETURN_ERROR; @@ -451,29 +436,13 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetLocalizedString, args, "Params: name, argum plString arg = "INVALID ARG"; if (item == Py_None) // none is allowed, but treated as a blank string arg = ""; - else if (PyUnicode_Check(item)) - { - int strLen = PyUnicode_GetSize(item); - wchar_t* buffer = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)item, buffer, strLen); - buffer[strLen] = L'\0'; - arg = plString::FromWchar(buffer); - delete [] buffer; - } - else if (PyString_Check(item)) - { - char* temp = PyString_AsString(item); - wchar_t* wTemp = hsStringToWString(temp); - arg = plString::FromWchar(wTemp); - delete [] wTemp; - } + arg = PyString_AsStringEx(item); // everything else won't throw an error, but will show up as INVALID ARG in the string argList.push_back(arg); } } - plString retVal = cyMisc::GetLocalizedString(name, argList); - return PyUnicode_FromWideChar(retVal.ToWchar(), retVal.GetSize()); + return PyUnicode_FromStringEx(cyMisc::GetLocalizedString(name, argList)); } PYTHON_GLOBAL_METHOD_DEFINITION(PtDumpLogs, args, "Params: folder\nDumps all current log files to the specified folder (a sub-folder to the log folder)") From 0efcebb2e937f9033f5403c4349a6876d551c459 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Sun, 13 Jan 2013 12:34:06 -0800 Subject: [PATCH 5/6] Fix substring indexing and whitespace. Fixes an off-by-one and off-by-initial-offset error, not clearing the stream between loops, and a few other edge conditions. --- .../pfLocalizationMgr/pfLocalizedString.cpp | 91 +++++++++++-------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp index 510735fe..a82c4d89 100644 --- a/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp +++ b/Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp @@ -69,8 +69,8 @@ pfLocalizedString::pfLocalizedString(const plString & plainText) void pfLocalizedString::IParameterize(const plString & inString) { textBlock curTextBlock; - fNumArguments = 0; // Reset the argument count. - fText.clear(); // Reset the text blocks. + fNumArguments = 0; // Reset the argument count. + fText.clear(); // Reset the text blocks. plString remainder = inString; plStringStream newText; @@ -79,61 +79,77 @@ void pfLocalizedString::IParameterize(const plString & inString) while (!remainder.IsEmpty()) { - // Check if we have any params. - nextToken = remainder.Find("%"); - if (nextToken != -1) - { - // Check it's not escaped. - if ((nextToken > 0) && (remainder.CharAt(nextToken-1) != '\\')) - { - // Check if it has an end. - int endToken = remainder.Substr(nextToken).Find("s"); - if (endToken != -1) - { - // Store existing block. - newText << remainder; + // Check if we have any params. + nextToken = remainder.Find("%"); + if (nextToken != -1) + { + // Check it's not escaped. + if ((nextToken == 0) || ((nextToken > 0) && (remainder.CharAt(nextToken-1) != '\\'))) + { + // Check if it has an end (ignoring any terminators we need to cross a space to find). + int endToken = remainder.Substr(nextToken).Find("s"); + if ((endToken != -1) && (remainder.Substr(nextToken, endToken).Find(" ") == -1)) + { + // Store existing block if it contains anything. + newText << remainder.Substr(0, nextToken); curTextBlock.fText = newText.GetString().Replace("\\\\", "\\"); - fText.push_back(curTextBlock); + if (!curTextBlock.fText.IsEmpty()) + { + fText.push_back(curTextBlock); + newText.Truncate(); + } - if (endToken == nextToken + 1) - { + if (endToken == nextToken + 1) + { // Store non-indexed param block. curTextBlock.fIsParam = true; curTextBlock.fParamIndex = curParameter++; curTextBlock.fText = ""; fText.push_back(curTextBlock); - } - else - { + } + else + { // Store indexed param block. curTextBlock.fIsParam = true; - curTextBlock.fParamIndex = remainder.Substr(nextToken, endToken-1).ToInt(10) - 1; // args start at 1 + curTextBlock.fParamIndex = remainder.Substr(nextToken + 1, endToken - 1).ToInt(10) - 1; // args start at 1 curTextBlock.fText = ""; fText.push_back(curTextBlock); - } + } curTextBlock.fIsParam = false; curTextBlock.fParamIndex = 0; fNumArguments++; - // Continue using the remaining string. - remainder = remainder.Substr(endToken+1); - } - } - else - { + // Continue, using the remaining string. + remainder = remainder.Substr(nextToken + endToken + 1); + } + else + { + // We have an unescaped but unterminated %. + // For now, let's just pretend it was escaped; + // This way they'll show up visibly in-game and will be reported. + newText << "%"; + remainder = remainder.Substr(nextToken + 1); + } + } + else + { // Copy the text up to the escape character, skip it, and continue. newText << remainder.Substr(0, nextToken - 1) << '%'; remainder = remainder.Substr(nextToken + 1); - } - } - else - { + } + } + else + { // We're done. Copy the remaining text and finish. newText << remainder; remainder = ""; curTextBlock.fText = newText.GetString().Replace("\\\\", "\\"); - fText.push_back(curTextBlock); - } + if (!curTextBlock.fText.IsEmpty()) + { + fText.push_back(curTextBlock); + newText.Truncate(); + } + } } } @@ -159,7 +175,7 @@ void pfLocalizedString::IUpdatePlainText() if (curTextBlock.fIsParam) { // Fill in parameter value. - ss << plString::Format("%%%ds", curTextBlock.fParamIndex + 1); + ss << "%%" << curTextBlock.fParamIndex + 1 << "s"; } else { @@ -192,8 +208,7 @@ void pfLocalizedString::IUpdateXML() if (curTextBlock.fIsParam) { // Fill in parameter value. - plString paramStr = plString::Format("%%%ds", curTextBlock.fParamIndex + 1); - ss << paramStr; + ss << "%%" << curTextBlock.fParamIndex + 1 << "s"; } else { From bcc97fa1dc2258f73b5314762bd0f389b8a6371e Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Mon, 14 Jan 2013 15:13:06 -0800 Subject: [PATCH 6/6] Update MaxComponent for pfLocalization changes. Adds limited plString usage to MaxComponent's plPickLocalizationDlg for compatibility with pfLocalizationDataMgr. --- Sources/Tools/MaxComponent/plPickLocalizationDlg.cpp | 12 ++++++------ Sources/Tools/MaxMain/GlobalUtility.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Tools/MaxComponent/plPickLocalizationDlg.cpp b/Sources/Tools/MaxComponent/plPickLocalizationDlg.cpp index 259ee36c..8992ddd8 100644 --- a/Sources/Tools/MaxComponent/plPickLocalizationDlg.cpp +++ b/Sources/Tools/MaxComponent/plPickLocalizationDlg.cpp @@ -129,20 +129,20 @@ HTREEITEM plPickLocalizationDlg::IAddVar(std::string name, std::string match, HT void plPickLocalizationDlg::IAddLocalizations(std::string ageName, std::string setName, std::string itemName) { - std::vector ages = pfLocalizationDataMgr::Instance().GetAgeList(); + std::vector ages = pfLocalizationDataMgr::Instance().GetAgeList(); for (int curAge = 0; curAge < ages.size(); curAge++) { - HTREEITEM hAgeItem = IAddVar(WStringToString(ages[curAge]), ageName, TVI_ROOT); + HTREEITEM hAgeItem = IAddVar(ages[curAge].c_str(), ageName, TVI_ROOT); - std::vector sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]); + std::vector sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]); for (int curSet = 0; curSet < sets.size(); curSet++) { - std::vector elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]); + std::vector elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]); - HTREEITEM hSetItem = IAddVar(WStringToString(sets[curSet]), setName, hAgeItem); + HTREEITEM hSetItem = IAddVar(sets[curSet].c_str(), setName, hAgeItem); for (int curElement = 0; curElement < elements.size(); curElement++) - IAddVar(WStringToString(elements[curElement]), itemName, hSetItem); + IAddVar(elements[curElement].c_str(), itemName, hSetItem); } } } diff --git a/Sources/Tools/MaxMain/GlobalUtility.cpp b/Sources/Tools/MaxMain/GlobalUtility.cpp index 9aa13c7b..a85c679b 100644 --- a/Sources/Tools/MaxMain/GlobalUtility.cpp +++ b/Sources/Tools/MaxMain/GlobalUtility.cpp @@ -230,7 +230,7 @@ DWORD PlasmaMax::Start() { std::string clientPath(pathTemp); clientPath += "dat"; - pfLocalizationMgr::Initialize(clientPath); + pfLocalizationMgr::Initialize(clientPath.c_str()); } return GUPRESULT_KEEP;