|
|
@ -84,34 +84,34 @@ public: |
|
|
|
static void XMLCALL HandleData(void *userData, const XML_Char *data, int stringLength); |
|
|
|
static void XMLCALL HandleData(void *userData, const XML_Char *data, int stringLength); |
|
|
|
friend class LocalizationDatabase; |
|
|
|
friend class LocalizationDatabase; |
|
|
|
|
|
|
|
|
|
|
|
// first wstring is language, second is data
|
|
|
|
// first string is language, second is data
|
|
|
|
typedef std::map<std::wstring, std::wstring> element; |
|
|
|
typedef std::map<plString, plString> element; |
|
|
|
|
|
|
|
|
|
|
|
// the wstring is the element name
|
|
|
|
// the string is the element name
|
|
|
|
typedef std::map<std::wstring, element> set; |
|
|
|
typedef std::map<plString, element> set; |
|
|
|
|
|
|
|
|
|
|
|
// the wstring is the set name
|
|
|
|
// the string is the set name
|
|
|
|
typedef std::map<std::wstring, set> age; |
|
|
|
typedef std::map<plString, set> age; |
|
|
|
|
|
|
|
|
|
|
|
// the wstring is the age name
|
|
|
|
// the string is the age name
|
|
|
|
typedef std::map<std::wstring, age> ageMap; |
|
|
|
typedef std::map<plString, age> ageMap; |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
bool fWeExploded; // alternative to massive error stack
|
|
|
|
bool fWeExploded; // alternative to massive error stack
|
|
|
|
std::string fFilename; |
|
|
|
plString fFilename; |
|
|
|
XML_Parser fParser; |
|
|
|
XML_Parser fParser; |
|
|
|
|
|
|
|
|
|
|
|
struct tagInfo |
|
|
|
struct tagInfo |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring fTag; |
|
|
|
plString fTag; |
|
|
|
std::map<std::wstring, std::wstring> fAttributes; |
|
|
|
std::map<plString, plString> fAttributes; |
|
|
|
}; |
|
|
|
}; |
|
|
|
std::stack<tagInfo> fTagStack; |
|
|
|
std::stack<tagInfo> fTagStack; |
|
|
|
|
|
|
|
|
|
|
|
int fSkipDepth; // if we need to skip a block, this is the depth we need to skip to
|
|
|
|
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?
|
|
|
|
bool fIgnoreContents; // are we ignoring the contents between tags?
|
|
|
|
std::wstring fCurrentAge, fCurrentSet, fCurrentElement, fCurrentTranslation; |
|
|
|
plString fCurrentAge, fCurrentSet, fCurrentElement, fCurrentTranslation; |
|
|
|
|
|
|
|
|
|
|
|
ageMap fData; |
|
|
|
ageMap fData; |
|
|
|
|
|
|
|
|
|
|
@ -126,8 +126,8 @@ protected: |
|
|
|
public: |
|
|
|
public: |
|
|
|
LocalizationXMLFile() : fWeExploded(false), fFilename("") { } |
|
|
|
LocalizationXMLFile() : fWeExploded(false), fFilename("") { } |
|
|
|
|
|
|
|
|
|
|
|
bool Parse(const std::string & fileName); // returns false on failure
|
|
|
|
bool Parse(const plString & fileName); // returns false on failure
|
|
|
|
void AddError(const plString& errorText); |
|
|
|
void AddError(const plString & errorText); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// A few small helper structs
|
|
|
|
// A few small helper structs
|
|
|
@ -177,12 +177,12 @@ XML_Memory_Handling_Suite gHeapAllocator = { |
|
|
|
//metmet remove static
|
|
|
|
//metmet remove static
|
|
|
|
void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *element, const XML_Char **attributes) |
|
|
|
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; |
|
|
|
LocalizationXMLFile *file = (LocalizationXMLFile*)userData; |
|
|
|
std::map<std::wstring, std::wstring> wAttributes; |
|
|
|
std::map<plString, plString> wAttributes; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; attributes[i]; i += 2) |
|
|
|
for (int i = 0; attributes[i]; i += 2) |
|
|
|
wAttributes[attributes[i]] = attributes[i+1]; |
|
|
|
wAttributes[plString::FromWchar(static_cast<const wchar_t *>(attributes[i]))] = plString::FromWchar(static_cast<const wchar_t *>(attributes[i+1])); |
|
|
|
|
|
|
|
|
|
|
|
LocalizationXMLFile::tagInfo parentTag; |
|
|
|
LocalizationXMLFile::tagInfo parentTag; |
|
|
|
if (!file->fTagStack.empty()) |
|
|
|
if (!file->fTagStack.empty()) |
|
|
@ -198,15 +198,15 @@ void XMLCALL LocalizationXMLFile::StartTag(void *userData, const XML_Char *eleme |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// now we handle this tag
|
|
|
|
// now we handle this tag
|
|
|
|
if (wElement == L"localizations") |
|
|
|
if (wElement == "localizations") |
|
|
|
file->IHandleLocalizationsTag(parentTag, newTag); |
|
|
|
file->IHandleLocalizationsTag(parentTag, newTag); |
|
|
|
else if (wElement == L"age") |
|
|
|
else if (wElement == "age") |
|
|
|
file->IHandleAgeTag(parentTag, newTag); |
|
|
|
file->IHandleAgeTag(parentTag, newTag); |
|
|
|
else if (wElement == L"set") |
|
|
|
else if (wElement == "set") |
|
|
|
file->IHandleSetTag(parentTag, newTag); |
|
|
|
file->IHandleSetTag(parentTag, newTag); |
|
|
|
else if (wElement == L"element") |
|
|
|
else if (wElement == "element") |
|
|
|
file->IHandleElementTag(parentTag, newTag); |
|
|
|
file->IHandleElementTag(parentTag, newTag); |
|
|
|
else if (wElement == L"translation") |
|
|
|
else if (wElement == "translation") |
|
|
|
file->IHandleTranslationTag(parentTag, newTag); |
|
|
|
file->IHandleTranslationTag(parentTag, newTag); |
|
|
|
else |
|
|
|
else |
|
|
|
file->AddError(plString::Format("Unknown tag %S found", wElement.c_str())); |
|
|
|
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
|
|
|
|
//metmet remove static and include the function inside LocalizationXMLFile
|
|
|
|
void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element) |
|
|
|
void XMLCALL LocalizationXMLFile::EndTag(void *userData, const XML_Char *element) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring wElement = element; |
|
|
|
plString wElement = plString::FromWchar(element); |
|
|
|
LocalizationXMLFile *file = (LocalizationXMLFile*)userData; |
|
|
|
LocalizationXMLFile *file = (LocalizationXMLFile*)userData; |
|
|
|
|
|
|
|
|
|
|
|
if (file->fSkipDepth != -1) // we're currently skipping
|
|
|
|
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
|
|
|
|
file->fSkipDepth = -1; // we're done skipping
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (wElement == L"age") // we left the age block
|
|
|
|
if (wElement == "age") // we left the age block
|
|
|
|
file->fCurrentAge = L""; |
|
|
|
file->fCurrentAge = ""; |
|
|
|
else if (wElement == L"set") // we left the set block
|
|
|
|
else if (wElement == "set") // we left the set block
|
|
|
|
file->fCurrentSet = L""; |
|
|
|
file->fCurrentSet = ""; |
|
|
|
else if (wElement == L"element") // we left the element block
|
|
|
|
else if (wElement == "element") // we left the element block
|
|
|
|
file->fCurrentElement = L""; |
|
|
|
file->fCurrentElement = ""; |
|
|
|
else if (wElement == L"translation") // we left the translation block
|
|
|
|
else if (wElement == "translation") // we left the translation block
|
|
|
|
{ |
|
|
|
{ |
|
|
|
file->fIgnoreContents = true; |
|
|
|
file->fIgnoreContents = true; |
|
|
|
file->fCurrentTranslation = L""; |
|
|
|
file->fCurrentTranslation = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file->fTagStack.pop(); |
|
|
|
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
|
|
|
|
// This gets all data between tags, including indentation and newlines
|
|
|
|
// so we'll have to ignore data when we aren't expecting it (not in a translation tag)
|
|
|
|
// so we'll have to ignore data when we aren't expecting it (not in a translation tag)
|
|
|
|
std::wstring wData = 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
|
|
|
|
// we must be in a translation tag since that's the only tag that doesn't ignore the contents
|
|
|
|
file->fData[file->fCurrentAge][file->fCurrentSet][file->fCurrentElement][file->fCurrentTranslation] += wData; |
|
|
|
file->fData[file->fCurrentAge][file->fCurrentSet][file->fCurrentElement][file->fCurrentTranslation] += wData; |
|
|
@ -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) |
|
|
|
void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (parentTag.fTag != L"") // we only allow <localizations> tags at root level
|
|
|
|
if (parentTag.fTag != "") // we only allow <localizations> tags at root level
|
|
|
|
{ |
|
|
|
{ |
|
|
|
AddError("localizations tag only allowed at root level"); |
|
|
|
AddError("localizations tag only allowed at root level"); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -277,20 +277,20 @@ void LocalizationXMLFile::IHandleLocalizationsTag(const LocalizationXMLFile::tag |
|
|
|
void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// it has to be inside the subtitles tag
|
|
|
|
// 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"); |
|
|
|
AddError("age tag can only be directly inside a localizations tag"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we have to have a name attribute
|
|
|
|
// we have to have a name attribute
|
|
|
|
if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) |
|
|
|
if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AddError("age tag is missing the name attribute"); |
|
|
|
AddError("age tag is missing the name attribute"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fCurrentAge = thisTag.fAttributes.find(L"name")->second; |
|
|
|
fCurrentAge = thisTag.fAttributes.find("name")->second; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IHandleSetTag() /////////////////////////////////////////////////
|
|
|
|
//// IHandleSetTag() /////////////////////////////////////////////////
|
|
|
@ -298,20 +298,20 @@ void LocalizationXMLFile::IHandleAgeTag(const LocalizationXMLFile::tagInfo & par |
|
|
|
void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// it has to be inside the age tag
|
|
|
|
// 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"); |
|
|
|
AddError("set tag can only be directly inside a age tag"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we have to have a name attribute
|
|
|
|
// we have to have a name attribute
|
|
|
|
if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) |
|
|
|
if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AddError("set tag is missing the name attribute"); |
|
|
|
AddError("set tag is missing the name attribute"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fCurrentSet = thisTag.fAttributes.find(L"name")->second; |
|
|
|
fCurrentSet = thisTag.fAttributes.find("name")->second; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IHandleElementTag() /////////////////////////////////////////////
|
|
|
|
//// IHandleElementTag() /////////////////////////////////////////////
|
|
|
@ -319,20 +319,20 @@ void LocalizationXMLFile::IHandleSetTag(const LocalizationXMLFile::tagInfo & par |
|
|
|
void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// it has to be inside the element tag
|
|
|
|
// 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"); |
|
|
|
AddError("element tag can only be directly inside a set tag"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we have to have a name attribute
|
|
|
|
// we have to have a name attribute
|
|
|
|
if (thisTag.fAttributes.find(L"name") == thisTag.fAttributes.end()) |
|
|
|
if (thisTag.fAttributes.find("name") == thisTag.fAttributes.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AddError("element tag is missing the name attribute"); |
|
|
|
AddError("element tag is missing the name attribute"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fCurrentElement = thisTag.fAttributes.find(L"name")->second; |
|
|
|
fCurrentElement = thisTag.fAttributes.find("name")->second; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IHandleTranslationTag() /////////////////////////////////////////
|
|
|
|
//// IHandleTranslationTag() /////////////////////////////////////////
|
|
|
@ -340,36 +340,36 @@ void LocalizationXMLFile::IHandleElementTag(const LocalizationXMLFile::tagInfo & |
|
|
|
void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
void LocalizationXMLFile::IHandleTranslationTag(const LocalizationXMLFile::tagInfo & parentTag, const LocalizationXMLFile::tagInfo & thisTag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// it has to be inside the element tag
|
|
|
|
// 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"); |
|
|
|
AddError("translation tag can only be directly inside a element tag"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we have to have a language attribute
|
|
|
|
// we have to have a language attribute
|
|
|
|
if (thisTag.fAttributes.find(L"language") == thisTag.fAttributes.end()) |
|
|
|
if (thisTag.fAttributes.find("language") == thisTag.fAttributes.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AddError("translation tag is missing the language attribute"); |
|
|
|
AddError("translation tag is missing the language attribute"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fIgnoreContents = false; // we now want contents between tags
|
|
|
|
fIgnoreContents = false; // we now want contents between tags
|
|
|
|
fCurrentTranslation = thisTag.fAttributes.find(L"language")->second; |
|
|
|
fCurrentTranslation = thisTag.fAttributes.find("language")->second; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// Parse() /////////////////////////////////////////////////////////
|
|
|
|
//// Parse() /////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool LocalizationXMLFile::Parse(const std::string & fileName) |
|
|
|
bool LocalizationXMLFile::Parse(const plString & fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fFilename = fileName; |
|
|
|
fFilename = fileName; |
|
|
|
|
|
|
|
|
|
|
|
while (!fTagStack.empty()) |
|
|
|
while (!fTagStack.empty()) |
|
|
|
fTagStack.pop(); |
|
|
|
fTagStack.pop(); |
|
|
|
|
|
|
|
|
|
|
|
fCurrentAge = L""; |
|
|
|
fCurrentAge = ""; |
|
|
|
fCurrentSet = L""; |
|
|
|
fCurrentSet = ""; |
|
|
|
fCurrentElement = L""; |
|
|
|
fCurrentElement = ""; |
|
|
|
fCurrentTranslation = L""; |
|
|
|
fCurrentTranslation = ""; |
|
|
|
|
|
|
|
|
|
|
|
fIgnoreContents = true; |
|
|
|
fIgnoreContents = true; |
|
|
|
fSkipDepth = -1; |
|
|
|
fSkipDepth = -1; |
|
|
@ -390,7 +390,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName) |
|
|
|
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str()); |
|
|
|
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFile(fileName.c_str()); |
|
|
|
if (!xmlStream) |
|
|
|
if (!xmlStream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
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; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -424,7 +424,7 @@ bool LocalizationXMLFile::Parse(const std::string & fileName) |
|
|
|
|
|
|
|
|
|
|
|
void LocalizationXMLFile::AddError(const plString& errorText) |
|
|
|
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()); |
|
|
|
XML_GetCurrentLineNumber(fParser), errorText.c_str()); |
|
|
|
fSkipDepth = fTagStack.size(); // skip this block
|
|
|
|
fSkipDepth = fTagStack.size(); // skip this block
|
|
|
|
fWeExploded = true; |
|
|
|
fWeExploded = true; |
|
|
@ -442,27 +442,27 @@ void LocalizationXMLFile::AddError(const plString& errorText) |
|
|
|
class LocalizationDatabase |
|
|
|
class LocalizationDatabase |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected: |
|
|
|
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<LocalizationXMLFile> fFiles; // the various XML files in that directory
|
|
|
|
std::vector<LocalizationXMLFile> fFiles; // the various XML files in that directory
|
|
|
|
|
|
|
|
|
|
|
|
LocalizationXMLFile::ageMap fData; |
|
|
|
LocalizationXMLFile::ageMap fData; |
|
|
|
|
|
|
|
|
|
|
|
LocalizationXMLFile::element IMergeElementData(LocalizationXMLFile::element firstElement, LocalizationXMLFile::element secondElement, 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 std::wstring & fileName, const std::wstring & 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 std::wstring & fileName, const std::wstring & 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 IMergeData(); // merge all localization data in the files
|
|
|
|
|
|
|
|
|
|
|
|
void IVerifyElement(const std::wstring &ageName, const std::wstring &setName, LocalizationXMLFile::set::iterator& curElement); |
|
|
|
void IVerifyElement(const plString &ageName, const plString &setName, LocalizationXMLFile::set::iterator& curElement); |
|
|
|
void IVerifySet(const std::wstring &ageName, const std::wstring &setName); |
|
|
|
void IVerifySet(const plString &ageName, const plString &setName); |
|
|
|
void IVerifyAge(const std::wstring &ageName); |
|
|
|
void IVerifyAge(const plString &ageName); |
|
|
|
void IVerifyData(); // verify the localization data once it has been merged in
|
|
|
|
void IVerifyData(); // verify the localization data once it has been merged in
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
LocalizationDatabase() {} |
|
|
|
LocalizationDatabase() {} |
|
|
|
|
|
|
|
|
|
|
|
void Parse(const std::string & directory); |
|
|
|
void Parse(const plString & directory); |
|
|
|
|
|
|
|
|
|
|
|
LocalizationXMLFile::ageMap GetData() {return fData;} |
|
|
|
LocalizationXMLFile::ageMap GetData() {return fData;} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -472,7 +472,7 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
//// IMergeElementData ///////////////////////////////////////////////
|
|
|
|
//// 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
|
|
|
|
// copy the data over, alerting the user to any duplicate translations
|
|
|
|
LocalizationXMLFile::element::iterator curTranslation; |
|
|
|
LocalizationXMLFile::element::iterator curTranslation; |
|
|
@ -492,7 +492,7 @@ LocalizationXMLFile::element LocalizationDatabase::IMergeElementData(Localizatio |
|
|
|
|
|
|
|
|
|
|
|
//// IMergeSetData ///////////////////////////////////////////////////
|
|
|
|
//// 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
|
|
|
|
// Merge all the elements
|
|
|
|
LocalizationXMLFile::set::iterator curElement; |
|
|
|
LocalizationXMLFile::set::iterator curElement; |
|
|
@ -502,7 +502,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile |
|
|
|
if (firstSet.find(curElement->first) == firstSet.end()) |
|
|
|
if (firstSet.find(curElement->first) == firstSet.end()) |
|
|
|
firstSet[curElement->first] = curElement->second; |
|
|
|
firstSet[curElement->first] = curElement->second; |
|
|
|
else // merge the element in
|
|
|
|
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; |
|
|
|
return firstSet; |
|
|
@ -510,7 +510,7 @@ LocalizationXMLFile::set LocalizationDatabase::IMergeSetData(LocalizationXMLFile |
|
|
|
|
|
|
|
|
|
|
|
//// IMergeAgeData ///////////////////////////////////////////////////
|
|
|
|
//// 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
|
|
|
|
// Merge all the sets
|
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
@ -520,7 +520,7 @@ LocalizationXMLFile::age LocalizationDatabase::IMergeAgeData(LocalizationXMLFile |
|
|
|
if (firstAge.find(curSet->first) == firstAge.end()) |
|
|
|
if (firstAge.find(curSet->first) == firstAge.end()) |
|
|
|
firstAge[curSet->first] = curSet->second; |
|
|
|
firstAge[curSet->first] = curSet->second; |
|
|
|
else // merge the data in
|
|
|
|
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; |
|
|
|
return firstAge; |
|
|
@ -532,11 +532,6 @@ void LocalizationDatabase::IMergeData() |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < fFiles.size(); i++) |
|
|
|
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 fileData = fFiles[i].fData; |
|
|
|
LocalizationXMLFile::ageMap::iterator curAge; |
|
|
|
LocalizationXMLFile::ageMap::iterator curAge; |
|
|
|
for (curAge = fileData.begin(); curAge != fileData.end(); curAge++) |
|
|
|
for (curAge = fileData.begin(); curAge != fileData.end(); curAge++) |
|
|
@ -545,29 +540,27 @@ void LocalizationDatabase::IMergeData() |
|
|
|
if (fData.find(curAge->first) == fData.end()) |
|
|
|
if (fData.find(curAge->first) == fData.end()) |
|
|
|
fData[curAge->first] = curAge->second; |
|
|
|
fData[curAge->first] = curAge->second; |
|
|
|
else // otherwise, merge the data in
|
|
|
|
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() ////////////////////////////////////////////////
|
|
|
|
//// 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::vector<plString> languageNames; |
|
|
|
std::wstring defaultLanguage; |
|
|
|
plString defaultLanguage; |
|
|
|
|
|
|
|
|
|
|
|
int numLocales = plLocalization::GetNumLocales(); |
|
|
|
int numLocales = plLocalization::GetNumLocales(); |
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
wchar_t *wName = hsStringToWString(name); |
|
|
|
languageNames.push_back(name); |
|
|
|
languageNames.push_back(wName); |
|
|
|
|
|
|
|
delete [] wName; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
defaultLanguage = languageNames[0]; |
|
|
|
defaultLanguage = languageNames[0]; |
|
|
|
|
|
|
|
|
|
|
|
std::wstring elementName = curElement->first; |
|
|
|
plString elementName = curElement->first; |
|
|
|
LocalizationXMLFile::element& theElement = curElement->second; |
|
|
|
LocalizationXMLFile::element& theElement = curElement->second; |
|
|
|
LocalizationXMLFile::element::iterator curTranslation = theElement.begin(); |
|
|
|
LocalizationXMLFile::element::iterator curTranslation = theElement.begin(); |
|
|
|
|
|
|
|
|
|
|
@ -606,13 +599,12 @@ void LocalizationDatabase::IVerifyElement(const std::wstring &ageName, const std |
|
|
|
|
|
|
|
|
|
|
|
//// IVerifySet() ////////////////////////////////////////////////////
|
|
|
|
//// 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& theSet = fData[ageName][setName]; |
|
|
|
LocalizationXMLFile::set::iterator curElement = theSet.begin(); |
|
|
|
LocalizationXMLFile::set::iterator curElement = theSet.begin(); |
|
|
|
wchar_t *wDefLang = hsStringToWString(plLocalization::GetLanguageName((plLocalization::Language)0)); |
|
|
|
|
|
|
|
std::wstring defaultLanguage = wDefLang; |
|
|
|
plString defaultLanguage = plLocalization::GetLanguageName((plLocalization::Language)0); |
|
|
|
delete [] wDefLang; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (curElement != theSet.end()) |
|
|
|
while (curElement != theSet.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -633,7 +625,7 @@ void LocalizationDatabase::IVerifySet(const std::wstring &ageName, const std::ws |
|
|
|
|
|
|
|
|
|
|
|
//// IVerifyAge() ////////////////////////////////////////////////////
|
|
|
|
//// IVerifyAge() ////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void LocalizationDatabase::IVerifyAge(const std::wstring &ageName) |
|
|
|
void LocalizationDatabase::IVerifyAge(const plString &ageName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LocalizationXMLFile::age& theAge = fData[ageName]; |
|
|
|
LocalizationXMLFile::age& theAge = fData[ageName]; |
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
@ -652,13 +644,13 @@ void LocalizationDatabase::IVerifyData() |
|
|
|
|
|
|
|
|
|
|
|
//// Parse() /////////////////////////////////////////////////////////
|
|
|
|
//// Parse() /////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void LocalizationDatabase::Parse(const std::string & directory) |
|
|
|
void LocalizationDatabase::Parse(const plString & directory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fDirectory = directory; |
|
|
|
fDirectory = directory; |
|
|
|
fFiles.clear(); |
|
|
|
fFiles.clear(); |
|
|
|
|
|
|
|
|
|
|
|
char filename[255]; |
|
|
|
char filename[255]; |
|
|
|
hsFolderIterator xmlFolder((directory+PATH_SEPARATOR_STR).c_str()); |
|
|
|
hsFolderIterator xmlFolder((directory + PATH_SEPARATOR_STR).c_str()); |
|
|
|
while(xmlFolder.NextFileSuffix(".loc")) |
|
|
|
while(xmlFolder.NextFileSuffix(".loc")) |
|
|
|
{ |
|
|
|
{ |
|
|
|
xmlFolder.GetPathAndName(filename); |
|
|
|
xmlFolder.GetPathAndName(filename); |
|
|
@ -685,30 +677,32 @@ void LocalizationDatabase::Parse(const std::string & directory) |
|
|
|
//// ISplitString() //////////////////////////////////////////////////
|
|
|
|
//// ISplitString() //////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
void pfLocalizationDataMgr::pf3PartMap<mapT>::ISplitString(std::wstring key, std::wstring &age, std::wstring &set, std::wstring &name) |
|
|
|
void pfLocalizationDataMgr::pf3PartMap<mapT>::ISplitString(plString key, plString &age, plString &set, plString &name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring::size_type periodLoc = key.find(L"."); |
|
|
|
int periodLoc = key.Find("."); |
|
|
|
age = key.substr(0, periodLoc); |
|
|
|
age = key.Substr(0, periodLoc); |
|
|
|
if (periodLoc >= key.length()) |
|
|
|
if (periodLoc >= key.GetSize()) { |
|
|
|
return; // don't get set or name if there isn't any period
|
|
|
|
return; // don't get set or name if there isn't any period
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
key = key.substr(periodLoc + 1, key.length()); |
|
|
|
key = key.Substr(periodLoc + 1, key.GetSize()); |
|
|
|
periodLoc = key.find(L"."); |
|
|
|
periodLoc = key.Find("."); |
|
|
|
set = key.substr(0, periodLoc); |
|
|
|
set = key.Substr(0, periodLoc); |
|
|
|
if (periodLoc >= key.length()) |
|
|
|
if (periodLoc >= key.GetSize()) { |
|
|
|
return; // don't get name if there isn't another period
|
|
|
|
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() ////////////////////////////////////////////////////////
|
|
|
|
//// exists() ////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
bool pfLocalizationDataMgr::pf3PartMap<mapT>::exists(const std::wstring & key) |
|
|
|
bool pfLocalizationDataMgr::pf3PartMap<mapT>::exists(const plString & key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring age, set, name; |
|
|
|
plString age, set, name; |
|
|
|
ISplitString(key, 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; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// now check individually
|
|
|
|
// now check individually
|
|
|
@ -726,11 +720,11 @@ bool pfLocalizationDataMgr::pf3PartMap<mapT>::exists(const std::wstring & key) |
|
|
|
//// setExists() /////////////////////////////////////////////////////
|
|
|
|
//// setExists() /////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
bool pfLocalizationDataMgr::pf3PartMap<mapT>::setExists(const std::wstring & key) |
|
|
|
bool pfLocalizationDataMgr::pf3PartMap<mapT>::setExists(const plString & key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring age, set, name; |
|
|
|
plString age, set, name; |
|
|
|
ISplitString(key, 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; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// now check individually
|
|
|
|
// now check individually
|
|
|
@ -746,11 +740,11 @@ bool pfLocalizationDataMgr::pf3PartMap<mapT>::setExists(const std::wstring & key |
|
|
|
//// erase() /////////////////////////////////////////////////////////
|
|
|
|
//// erase() /////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
void pfLocalizationDataMgr::pf3PartMap<mapT>::erase(const std::wstring & key) |
|
|
|
void pfLocalizationDataMgr::pf3PartMap<mapT>::erase(const plString & key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring age, set, name; |
|
|
|
plString age, set, name; |
|
|
|
ISplitString(key, 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; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// now check individually
|
|
|
|
// now check individually
|
|
|
@ -772,9 +766,9 @@ void pfLocalizationDataMgr::pf3PartMap<mapT>::erase(const std::wstring & key) |
|
|
|
//// operator[]() ////////////////////////////////////////////////////
|
|
|
|
//// operator[]() ////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
mapT &pfLocalizationDataMgr::pf3PartMap<mapT>::operator[](const std::wstring &key) |
|
|
|
mapT &pfLocalizationDataMgr::pf3PartMap<mapT>::operator[](const plString &key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring age, set, name; |
|
|
|
plString age, set, name; |
|
|
|
ISplitString(key, age, set, name); |
|
|
|
ISplitString(key, age, set, name); |
|
|
|
return fData[age][set][name]; |
|
|
|
return fData[age][set][name]; |
|
|
|
} |
|
|
|
} |
|
|
@ -782,9 +776,9 @@ mapT &pfLocalizationDataMgr::pf3PartMap<mapT>::operator[](const std::wstring &ke |
|
|
|
//// getAgeList() ////////////////////////////////////////////////////
|
|
|
|
//// getAgeList() ////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
WStringVector pfLocalizationDataMgr::pf3PartMap<mapT>::getAgeList() |
|
|
|
std::vector<plString> pfLocalizationDataMgr::pf3PartMap<mapT>::getAgeList() |
|
|
|
{ |
|
|
|
{ |
|
|
|
WStringVector retVal; |
|
|
|
std::vector<plString> retVal; |
|
|
|
typename ThreePartMap::iterator curAge; |
|
|
|
typename ThreePartMap::iterator curAge; |
|
|
|
|
|
|
|
|
|
|
|
for (curAge = fData.begin(); curAge != fData.end(); curAge++) |
|
|
|
for (curAge = fData.begin(); curAge != fData.end(); curAge++) |
|
|
@ -796,10 +790,10 @@ WStringVector pfLocalizationDataMgr::pf3PartMap<mapT>::getAgeList() |
|
|
|
//// getSetList() ////////////////////////////////////////////////////
|
|
|
|
//// getSetList() ////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
WStringVector pfLocalizationDataMgr::pf3PartMap<mapT>::getSetList(const std::wstring & age) |
|
|
|
std::vector<plString> pfLocalizationDataMgr::pf3PartMap<mapT>::getSetList(const plString & age) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WStringVector retVal; |
|
|
|
std::vector<plString> retVal; |
|
|
|
typename std::map<std::wstring, std::map<std::wstring, mapT> >::iterator curSet; |
|
|
|
typename std::map<plString, std::map<plString, mapT> >::iterator curSet; |
|
|
|
|
|
|
|
|
|
|
|
if (fData.find(age) == fData.end()) |
|
|
|
if (fData.find(age) == fData.end()) |
|
|
|
return retVal; // return an empty list, the age doesn't exist
|
|
|
|
return retVal; // return an empty list, the age doesn't exist
|
|
|
@ -813,10 +807,10 @@ WStringVector pfLocalizationDataMgr::pf3PartMap<mapT>::getSetList(const std::wst |
|
|
|
//// getNameList() ///////////////////////////////////////////////////
|
|
|
|
//// getNameList() ///////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
template<class mapT> |
|
|
|
template<class mapT> |
|
|
|
WStringVector pfLocalizationDataMgr::pf3PartMap<mapT>::getNameList(const std::wstring & age, const std::wstring & set) |
|
|
|
std::vector<plString> pfLocalizationDataMgr::pf3PartMap<mapT>::getNameList(const plString & age, const plString & set) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WStringVector retVal; |
|
|
|
std::vector<plString> retVal; |
|
|
|
typename std::map<std::wstring, mapT>::iterator curName; |
|
|
|
typename std::map<plString, mapT>::iterator curName; |
|
|
|
|
|
|
|
|
|
|
|
if (fData.find(age) == fData.end()) |
|
|
|
if (fData.find(age) == fData.end()) |
|
|
|
return retVal; // return an empty list, the age doesn't exist
|
|
|
|
return retVal; // return an empty list, the age doesn't exist
|
|
|
@ -839,7 +833,7 @@ plStatusLog *pfLocalizationDataMgr::fLog = nil; // output logfile |
|
|
|
|
|
|
|
|
|
|
|
//// Constructor/Destructor //////////////////////////////////////////
|
|
|
|
//// 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!"); |
|
|
|
hsAssert(!fInstance, "Tried to create the localization data manager more than once!"); |
|
|
|
fInstance = this; |
|
|
|
fInstance = this; |
|
|
@ -869,10 +863,8 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE |
|
|
|
|
|
|
|
|
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
wchar_t *wName = hsStringToWString(name); |
|
|
|
retVal[name] = ""; |
|
|
|
retVal[wName] = L""; |
|
|
|
|
|
|
|
delete [] wName; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return retVal; |
|
|
|
return retVal; |
|
|
@ -880,29 +872,23 @@ pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedE |
|
|
|
|
|
|
|
|
|
|
|
//// IGetCurrentLanguageName /////////////////////////////////////////
|
|
|
|
//// IGetCurrentLanguageName /////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring pfLocalizationDataMgr::IGetCurrentLanguageName() |
|
|
|
plString pfLocalizationDataMgr::IGetCurrentLanguageName() |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring retVal; |
|
|
|
plString retVal = plLocalization::GetLanguageName(plLocalization::GetLanguage()); |
|
|
|
const char *name = plLocalization::GetLanguageName(plLocalization::GetLanguage()); |
|
|
|
|
|
|
|
wchar_t *wName = hsStringToWString(name); |
|
|
|
|
|
|
|
retVal = wName; |
|
|
|
|
|
|
|
delete [] wName; |
|
|
|
|
|
|
|
return retVal; |
|
|
|
return retVal; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IGetAllLanguageNames ////////////////////////////////////////////
|
|
|
|
//// IGetAllLanguageNames ////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
WStringVector pfLocalizationDataMgr::IGetAllLanguageNames() |
|
|
|
std::vector<plString> pfLocalizationDataMgr::IGetAllLanguageNames() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int numLocales = plLocalization::GetNumLocales(); |
|
|
|
int numLocales = plLocalization::GetNumLocales(); |
|
|
|
WStringVector retVal; |
|
|
|
std::vector<plString> retVal; |
|
|
|
|
|
|
|
|
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
for (int curLocale = 0; curLocale <= numLocales; curLocale++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
plString name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); |
|
|
|
wchar_t *wName = hsStringToWString(name); |
|
|
|
retVal.push_back(name); |
|
|
|
retVal.push_back(wName); |
|
|
|
|
|
|
|
delete [] wName; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return retVal; |
|
|
|
return retVal; |
|
|
@ -910,7 +896,7 @@ WStringVector pfLocalizationDataMgr::IGetAllLanguageNames() |
|
|
|
|
|
|
|
|
|
|
|
//// IConvertSubtitle ////////////////////////////////////////////////
|
|
|
|
//// IConvertSubtitle ////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const std::wstring & curPath) |
|
|
|
void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const plString & curPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pfLocalizationDataMgr::localizedElement newElement; |
|
|
|
pfLocalizationDataMgr::localizedElement newElement; |
|
|
|
int16_t numArgs = -1; |
|
|
|
int16_t numArgs = -1; |
|
|
@ -931,7 +917,7 @@ void pfLocalizationDataMgr::IConvertElement(LocElementInfo *elementInfo, const s |
|
|
|
|
|
|
|
|
|
|
|
//// IConvertSet /////////////////////////////////////////////////////
|
|
|
|
//// IConvertSet /////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const std::wstring & curPath) |
|
|
|
void pfLocalizationDataMgr::IConvertSet(LocSetInfo *setInfo, const plString & curPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LocalizationXMLFile::set::iterator curElement; |
|
|
|
LocalizationXMLFile::set::iterator curElement; |
|
|
|
for (curElement = setInfo->fSet.begin(); curElement != setInfo->fSet.end(); 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; |
|
|
|
LocElementInfo elementInfo; |
|
|
|
elementInfo.fElement = curElement->second; |
|
|
|
elementInfo.fElement = curElement->second; |
|
|
|
|
|
|
|
|
|
|
|
IConvertElement(&elementInfo, curPath + L"." + curElement->first); |
|
|
|
IConvertElement(&elementInfo, plString::Format("%S.%S", curPath.c_str(), curElement->first.c_str())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IConvertAge /////////////////////////////////////////////////////
|
|
|
|
//// IConvertAge /////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const std::wstring & curPath) |
|
|
|
void pfLocalizationDataMgr::IConvertAge(LocAgeInfo *ageInfo, const plString & curPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
|
LocalizationXMLFile::age::iterator curSet; |
|
|
|
for (curSet = ageInfo->fAge.begin(); curSet != ageInfo->fAge.end(); 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; |
|
|
|
LocSetInfo setInfo; |
|
|
|
setInfo.fSet = curSet->second; |
|
|
|
setInfo.fSet = curSet->second; |
|
|
|
|
|
|
|
|
|
|
|
IConvertSet(&setInfo, curPath + L"." + curSet->first); |
|
|
|
IConvertSet(&setInfo, plString::Format("%S.%S", curPath.c_str(), curSet->first.c_str())); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// 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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return retVal; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// IWriteText //////////////////////////////////////////////////////
|
|
|
|
//// 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 weWroteData = false; // did we actually write any data of consequence?
|
|
|
|
bool setEmpty = true; |
|
|
|
bool setEmpty = true; |
|
|
|
|
|
|
|
|
|
|
|
// we will try to pretty print it all so it's easy to read for the devs
|
|
|
|
// we will try to pretty print it all so it's easy to read for the devs
|
|
|
|
std::wstring fileData = L"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n"; // stores the xml we are going to write to the file (UTF-16 format)
|
|
|
|
plStringStream fileData; |
|
|
|
fileData += L"<localizations>\n"; |
|
|
|
fileData << "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n"; // stores the xml we are going to write to the file (UTF-16 format)
|
|
|
|
fileData += L"\t<age name=\"" + ageName + L"\">\n"; |
|
|
|
fileData << "<localizations>\n"; |
|
|
|
|
|
|
|
fileData << plString::Format("\t<age name=\"%S\">\n", ageName.c_str()); |
|
|
|
|
|
|
|
|
|
|
|
WStringVector setNames = GetSetList(ageName); |
|
|
|
std::vector<plString> setNames = GetSetList(ageName); |
|
|
|
for (int curSet = 0; curSet < setNames.size(); curSet++) |
|
|
|
for (int curSet = 0; curSet < setNames.size(); curSet++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setEmpty = true; // so far, this set is empty
|
|
|
|
setEmpty = true; // so far, this set is empty
|
|
|
|
std::wstring setCode = L""; |
|
|
|
plStringStream setCode; |
|
|
|
setCode += L"\t\t<set name=\"" + setNames[curSet] + L"\">\n"; |
|
|
|
setCode << plString::Format("\t\t<set name=\"%S\">\n", setNames[curSet].c_str()); |
|
|
|
|
|
|
|
|
|
|
|
WStringVector elementNames = GetElementList(ageName, setNames[curSet]); |
|
|
|
std::vector<plString> elementNames = GetElementList(ageName, setNames[curSet]); |
|
|
|
for (int curElement = 0; curElement < elementNames.size(); curElement++) |
|
|
|
for (int curElement = 0; curElement < elementNames.size(); curElement++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setCode += L"\t\t\t<element name=\"" + elementNames[curElement] + L"\">\n"; |
|
|
|
setCode << plString::Format("\t\t\t<element name=\"%S\">\n", elementNames[curElement].c_str()); |
|
|
|
std::wstring key = ageName + L"." + setNames[curSet] + L"." + elementNames[curElement]; |
|
|
|
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()) |
|
|
|
if (fLocalizedElements[key].find(languageName) != fLocalizedElements[key].end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring key = ageName + L"." + setNames[curSet] + L"." + elementNames[curElement]; |
|
|
|
|
|
|
|
weWroteData = true; |
|
|
|
weWroteData = true; |
|
|
|
setEmpty = false; |
|
|
|
setEmpty = false; |
|
|
|
setCode += L"\t\t\t\t<translation language=\"" + languageName + L"\">"; |
|
|
|
setCode << plString::Format("\t\t\t\t<translation language=\"%S\">", languageName.c_str()); |
|
|
|
setCode += fLocalizedElements[key][languageName].ToXML(); |
|
|
|
setCode << fLocalizedElements[key][languageName].ToXML(); |
|
|
|
setCode += L"</translation>\n"; |
|
|
|
setCode << "</translation>\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setCode += L"\t\t\t</element>\n"; |
|
|
|
setCode << "\t\t\t</element>\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setCode += L"\t\t</set>\n"; |
|
|
|
setCode << "\t\t</set>\n"; |
|
|
|
|
|
|
|
|
|
|
|
if (!setEmpty) |
|
|
|
if (!setEmpty) |
|
|
|
fileData += setCode; |
|
|
|
fileData << setCode.GetString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fileData += L"\t</age>\n"; |
|
|
|
fileData << "\t</age>\n"; |
|
|
|
fileData += L"</localizations>\n"; |
|
|
|
fileData << "</localizations>\n"; |
|
|
|
|
|
|
|
|
|
|
|
if (weWroteData) |
|
|
|
if (weWroteData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// now spit the results out to the file
|
|
|
|
// now spit the results out to the file
|
|
|
|
uint32_t numBytes; |
|
|
|
|
|
|
|
char *byteStream = IConvertToByteStream(fileData, numBytes); |
|
|
|
|
|
|
|
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename.c_str()); |
|
|
|
hsStream *xmlStream = plEncryptedStream::OpenEncryptedFileWrite(filename.c_str()); |
|
|
|
xmlStream->Write(numBytes, byteStream); |
|
|
|
xmlStream->Write(fileData.GetLength(), fileData.GetString().c_str()); |
|
|
|
xmlStream->Close(); |
|
|
|
xmlStream->Close(); |
|
|
|
delete xmlStream; |
|
|
|
delete xmlStream; |
|
|
|
delete [] byteStream; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// Initialize //////////////////////////////////////////////////////
|
|
|
|
//// Initialize //////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::Initialize(const std::string & path) |
|
|
|
void pfLocalizationDataMgr::Initialize(const plString & path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fInstance) |
|
|
|
if (fInstance) |
|
|
|
return; |
|
|
|
return; |
|
|
@ -1102,17 +1060,17 @@ void pfLocalizationDataMgr::SetupData() |
|
|
|
|
|
|
|
|
|
|
|
//// GetElement //////////////////////////////////////////////////////
|
|
|
|
//// 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
|
|
|
|
pfLocalizedString retVal; // if this returns before we initialize it, it will be empty, indicating failure
|
|
|
|
|
|
|
|
|
|
|
|
if (!fLocalizedElements.exists(name)) // does the requested element exist?
|
|
|
|
if (!fLocalizedElements.exists(name)) // does the requested element exist?
|
|
|
|
return retVal; // nope, so return failure
|
|
|
|
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
|
|
|
|
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
|
|
|
|
if (fLocalizedElements[name].find(languageName) == fLocalizedElements[name].end()) // make sure english exists
|
|
|
|
return retVal; // language doesn't exist
|
|
|
|
return retVal; // language doesn't exist
|
|
|
|
} |
|
|
|
} |
|
|
@ -1122,7 +1080,7 @@ pfLocalizedString pfLocalizationDataMgr::GetElement(const std::wstring & name) |
|
|
|
|
|
|
|
|
|
|
|
//// GetSpecificElement //////////////////////////////////////////////
|
|
|
|
//// 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
|
|
|
|
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 ////////////////////////////////////////////////////
|
|
|
|
//// GetLanguages ////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, const std::wstring & setName, const std::wstring & elementName) |
|
|
|
std::vector<plString> pfLocalizationDataMgr::GetLanguages(const plString & ageName, const plString & setName, const plString & elementName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WStringVector retVal; |
|
|
|
std::vector<plString> retVal; |
|
|
|
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 (fLocalizedElements.exists(key)) |
|
|
|
if (fLocalizedElements.exists(key)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// age, set, and element exists
|
|
|
|
// age, set, and element exists
|
|
|
@ -1149,8 +1107,8 @@ WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, |
|
|
|
localizedElement::iterator curLanguage; |
|
|
|
localizedElement::iterator curLanguage; |
|
|
|
for (curLanguage = elem.begin(); curLanguage != elem.end(); curLanguage++) |
|
|
|
for (curLanguage = elem.begin(); curLanguage != elem.end(); curLanguage++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring language = curLanguage->first; |
|
|
|
plString language = curLanguage->first; |
|
|
|
if (!language.empty()) // somehow blank language names sneak in... so don't return them
|
|
|
|
if (!language.IsEmpty()) // somehow blank language names sneak in... so don't return them
|
|
|
|
retVal.push_back(curLanguage->first); |
|
|
|
retVal.push_back(curLanguage->first); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1159,9 +1117,9 @@ WStringVector pfLocalizationDataMgr::GetLanguages(const std::wstring & ageName, |
|
|
|
|
|
|
|
|
|
|
|
//// GetElementXMLData ///////////////////////////////////////////////
|
|
|
|
//// 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.exists(name)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) |
|
|
|
if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) |
|
|
@ -1172,9 +1130,9 @@ std::wstring pfLocalizationDataMgr::GetElementXMLData(const std::wstring & name, |
|
|
|
|
|
|
|
|
|
|
|
//// GetElementPlainTextData /////////////////////////////////////////
|
|
|
|
//// 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.exists(name)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) |
|
|
|
if (fLocalizedElements[name].find(languageName) != fLocalizedElements[name].end()) |
|
|
@ -1185,7 +1143,7 @@ std::wstring pfLocalizationDataMgr::GetElementPlainTextData(const std::wstring & |
|
|
|
|
|
|
|
|
|
|
|
//// SetElementXMLData ///////////////////////////////////////////////
|
|
|
|
//// 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)) |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
return false; // doesn't exist
|
|
|
|
return false; // doesn't exist
|
|
|
@ -1196,7 +1154,7 @@ bool pfLocalizationDataMgr::SetElementXMLData(const std::wstring & name, const s |
|
|
|
|
|
|
|
|
|
|
|
//// SetElementPlainTextData /////////////////////////////////////////
|
|
|
|
//// 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)) |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
return false; // doesn't exist
|
|
|
|
return false; // doesn't exist
|
|
|
@ -1207,31 +1165,31 @@ bool pfLocalizationDataMgr::SetElementPlainTextData(const std::wstring & name, c |
|
|
|
|
|
|
|
|
|
|
|
//// AddLocalization /////////////////////////////////////////////////
|
|
|
|
//// 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)) |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
return false; // doesn't exist
|
|
|
|
return false; // doesn't exist
|
|
|
|
|
|
|
|
|
|
|
|
// copy the english over so it can be localized
|
|
|
|
// copy the english over so it can be localized
|
|
|
|
fLocalizedElements[name][newLanguage] = fLocalizedElements[name][L"English"]; |
|
|
|
fLocalizedElements[name][newLanguage] = fLocalizedElements[name]["English"]; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// AddElement //////////////////////////////////////////////////////
|
|
|
|
//// AddElement //////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool pfLocalizationDataMgr::AddElement(const std::wstring & name) |
|
|
|
bool pfLocalizationDataMgr::AddElement(const plString & name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fLocalizedElements.exists(name)) |
|
|
|
if (fLocalizedElements.exists(name)) |
|
|
|
return false; // already exists
|
|
|
|
return false; // already exists
|
|
|
|
|
|
|
|
|
|
|
|
pfLocalizedString newElement; |
|
|
|
pfLocalizedString newElement; |
|
|
|
fLocalizedElements[name][L"English"] = newElement; |
|
|
|
fLocalizedElements[name]["English"] = newElement; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// DeleteLocalization //////////////////////////////////////////////
|
|
|
|
//// 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)) |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
return false; // doesn't exist
|
|
|
|
return false; // doesn't exist
|
|
|
@ -1245,7 +1203,7 @@ bool pfLocalizationDataMgr::DeleteLocalization(const std::wstring & name, const |
|
|
|
|
|
|
|
|
|
|
|
//// DeleteElement ///////////////////////////////////////////////////
|
|
|
|
//// DeleteElement ///////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool pfLocalizationDataMgr::DeleteElement(const std::wstring & name) |
|
|
|
bool pfLocalizationDataMgr::DeleteElement(const plString & name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
if (!fLocalizedElements.exists(name)) |
|
|
|
return false; // doesn't exist
|
|
|
|
return false; // doesn't exist
|
|
|
@ -1257,24 +1215,16 @@ bool pfLocalizationDataMgr::DeleteElement(const std::wstring & name) |
|
|
|
|
|
|
|
|
|
|
|
//// WriteDatabaseToDisk /////////////////////////////////////////////
|
|
|
|
//// WriteDatabaseToDisk /////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::WriteDatabaseToDisk(const std::string & path) |
|
|
|
void pfLocalizationDataMgr::WriteDatabaseToDisk(const plString & path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// first, write the styles and panel settings to styles.sub
|
|
|
|
// first, write the styles and panel settings to styles.sub
|
|
|
|
WStringVector ageNames = GetAgeList(); |
|
|
|
std::vector<plString> ageNames = GetAgeList(); |
|
|
|
WStringVector languageNames = IGetAllLanguageNames(); |
|
|
|
std::vector<plString> languageNames = IGetAllLanguageNames(); |
|
|
|
for (int curAge = 0; curAge < ageNames.size(); curAge++) |
|
|
|
for (int curAge = 0; curAge < ageNames.size(); curAge++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++) |
|
|
|
for (int curLanguage = 0; curLanguage < languageNames.size(); curLanguage++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string cAgeName, cLanguageName; |
|
|
|
IWriteText(plString::Format("%S/%S%S.loc", path, ageNames[curAge].c_str(), languageNames[curLanguage].c_str()), ageNames[curAge], languageNames[curLanguage]); |
|
|
|
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]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1283,26 +1233,26 @@ void pfLocalizationDataMgr::WriteDatabaseToDisk(const std::string & path) |
|
|
|
|
|
|
|
|
|
|
|
void pfLocalizationDataMgr::OutputTreeToLog() |
|
|
|
void pfLocalizationDataMgr::OutputTreeToLog() |
|
|
|
{ |
|
|
|
{ |
|
|
|
WStringVector ages = GetAgeList(); |
|
|
|
std::vector<plString> ages = GetAgeList(); |
|
|
|
|
|
|
|
|
|
|
|
fLog->AddLine("\n"); |
|
|
|
fLog->AddLine("\n"); |
|
|
|
fLog->AddLine("Localization tree:\n"); |
|
|
|
fLog->AddLine("Localization tree:\n"); |
|
|
|
|
|
|
|
|
|
|
|
for (WStringVector::iterator i = ages.begin(); i != ages.end(); ++i) |
|
|
|
for (std::vector<plString>::iterator i = ages.begin(); i != ages.end(); ++i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring age = *i; |
|
|
|
plString age = *i; |
|
|
|
fLog->AddLineF("\t%S", age.c_str()); |
|
|
|
fLog->AddLineF("\t%S", age.c_str()); |
|
|
|
|
|
|
|
|
|
|
|
WStringVector sets = GetSetList(age); |
|
|
|
std::vector<plString> sets = GetSetList(age); |
|
|
|
for (WStringVector::iterator j = sets.begin(); j != sets.end(); ++j) |
|
|
|
for (std::vector<plString>::iterator j = sets.begin(); j != sets.end(); ++j) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring set = (*j); |
|
|
|
plString set = (*j); |
|
|
|
fLog->AddLineF("\t\t%S", set.c_str()); |
|
|
|
fLog->AddLineF("\t\t%S", set.c_str()); |
|
|
|
|
|
|
|
|
|
|
|
WStringVector names = GetElementList(age, set); |
|
|
|
std::vector<plString> names = GetElementList(age, set); |
|
|
|
for (WStringVector::iterator k = names.begin(); k != names.end(); ++k) |
|
|
|
for (std::vector<plString>::iterator k = names.begin(); k != names.end(); ++k) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::wstring name = (*k); |
|
|
|
plString name = (*k); |
|
|
|
fLog->AddLineF("\t\t\t%S", name.c_str()); |
|
|
|
fLog->AddLineF("\t\t\t%S", name.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|