/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsTypes.h"
#include "plLocalization.h"
#include "plFile/plFileUtils.h"
#include "hsUtils.h"
plLocalization::Language plLocalization::fLanguage = plLocalization::kEnglish;
const char* plLocalization::fLangTags[] =
{
"_eng", // kEnglish
"_fre", // kFrench
"_ger", // kGerman
"_spa", // kSpanish
"_ita", // kItalian
"_jpn" // kJapanese
};
const int kLangTagLen = 4;
const char* plLocalization::fLangNames[] =
{
"English", // kEnglish
"French", // kFrench
"German", // kGerman
"Spanish", // kSpanish
"Italian", // kItalian
"Japanese" // kJapanese
};
bool plLocalization::fUsesUnicode[] =
{
false, // kEnglish
false, // kFrench
false, // kGerman
false, // kSpanish
false, // kItalian
true // kJapanese
};
plLocalization::encodingTypes plLocalization::fUnicodeEncoding[] =
{
Enc_Unencoded, // kEnglish
Enc_Unencoded, // kFrench
Enc_Unencoded, // kGerman
Enc_Unencoded, // kSpanish
Enc_Unencoded, // kItalian
Enc_UTF8, // kJapanese
};
hsBool plLocalization::IGetLocalized(const char* name, Language lang, char* localizedName)
{
const char* underscore = strrchr(name, '_');
if (underscore)
{
char langTag[kLangTagLen+1];
strncpy(langTag,underscore,kLangTagLen);
langTag[kLangTagLen] = '\0';
if (strncmp(langTag, fLangTags[kEnglish], kLangTagLen) == 0)
{
if (localizedName)
{
strcpy(localizedName, name);
int underscorePos = underscore - name;
memcpy(localizedName + underscorePos, fLangTags[lang], kLangTagLen);
}
return true;
}
}
return false;
}
hsBool plLocalization::ExportGetLocalized(const char* name, int lang, char* localizedName)
{
return IGetLocalized(name, Language(lang+1), localizedName) &&
plFileUtils::FileExists(localizedName);
}
std::string plLocalization::LocalToString(const std::vector & localizedText)
{
std::string retVal = "";
for (int i=0; i kNumLanguages-1)
break;
std::string langHeader = "$";
std::string langName = GetLanguageName((Language)i);
langHeader += langName.substr(0,2) + "$";
retVal += langHeader + localizedText[i];
}
return retVal;
}
std::vector plLocalization::StringToLocal(const std::string & localizedText)
{
std::vector retVal;
wchar_t *temp = hsStringToWString(localizedText.c_str());
std::wstring wLocalizedText = temp;
delete [] temp;
std::vector wStringVector = StringToLocal(wLocalizedText);
int i;
for (i=0; i plLocalization::StringToLocal(const std::wstring & localizedText)
{
std::vector tags;
std::vector tagLocs;
std::vector sortedTagLocs;
std::vector retVal;
int i;
for (i=0; i tagLocs[sortedTagLocs[j]])
sortedTagLocs[i]^=sortedTagLocs[j]^=sortedTagLocs[i]^=sortedTagLocs[j]; // swap the contents (yes, it works)
}
}
// now sortedTagLocs has the indexes of tagLocs sorted from smallest loc to highest loc
hsBool noTags = true;
for (i=0; i