Skip to content

Commit

Permalink
add ConvertWindowsToGeneralCharCode to CLangCodeExpander to get the n…
Browse files Browse the repository at this point in the history
…on-win32-specific three char code from a win32-specific one
  • Loading branch information
Montellese committed May 7, 2012
1 parent 240692b commit 7c2ed63
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
3 changes: 3 additions & 0 deletions xbmc/LangInfo.h
Expand Up @@ -37,6 +37,9 @@ class CLangInfo
CStdString GetGuiCharSet() const;
CStdString GetSubtitleCharSet() const;

// three char language code (not win32 specific)
const CStdString& GetLanguageCode() const { return m_languageCodeGeneral; }

const CStdString& GetDVDMenuLanguage() const;
const CStdString& GetDVDAudioLanguage() const;
const CStdString& GetDVDSubtitleLanguage() const;
Expand Down
68 changes: 67 additions & 1 deletion xbmc/utils/LangCodeExpander.cpp
Expand Up @@ -21,6 +21,7 @@

#include "LangCodeExpander.h"
#include "utils/XBMCTinyXML.h"
#include "LangInfo.h"
#include "utils/log.h"

#define MAKECODE(a, b, c, d) ((((long)(a))<<24) | (((long)(b))<<16) | (((long)(c))<<8) | (long)(d))
Expand Down Expand Up @@ -141,7 +142,7 @@ bool CLangCodeExpander::Lookup(CStdString& desc, const int code)
return Lookup(desc, lang);
}

#ifdef _WIN32
#ifdef TARGET_WINDOWS
bool CLangCodeExpander::ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode, bool localeHack /*= false*/)
#else
bool CLangCodeExpander::ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode)
Expand Down Expand Up @@ -175,6 +176,50 @@ bool CLangCodeExpander::ConvertTwoToThreeCharCode(CStdString& strThreeCharCode,
return false;
}

#ifdef TARGET_WINDOWS
bool CLangCodeExpander::ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode, bool localeHack /*= false*/)
#else
bool CLangCodeExpander::ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode)
#endif
{
if (strCharCode.size() == 2)
#ifdef TARGET_WINDOWS
return g_LangCodeExpander.ConvertTwoToThreeCharCode(strThreeCharCode, strCharCode, localeHack);
#else
return g_LangCodeExpander.ConvertTwoToThreeCharCode(strThreeCharCode, strCharCode);
#endif
else if (strCharCode.size() == 3)
{
for (unsigned int index = 0; index < sizeof(CharCode2To3) / sizeof(CharCode2To3[0]); ++index)
{
#ifdef TARGET_WINDOWS
if (strCharCode.Equals(CharCode2To3[index].id) ||
(localeHack && CharCode2To3[index].win_id != NULL && strCharCode.Equals(CharCode2To3[index].win_id)))
#else
if (strCharCode.Equals(CharCode2To3[index].id))
#endif
{
strThreeCharCode = strCharCode;
return true;
}
}
}
else if (strCharCode.size() > 3)
{
CStdString strLangInfoPath;
strLangInfoPath.Format("special://xbmc/language/%s/langinfo.xml", strCharCode.c_str());
CLangInfo langInfo;
if (!langInfo.Load(strLangInfoPath))
return false;

strThreeCharCode = langInfo.GetLanguageCode();
return true;
}

return false;
}

#ifdef TARGET_WINDOWS
bool CLangCodeExpander::ConvertLinuxToWindowsRegionCodes(const CStdString& strTwoCharCode, CStdString& strThreeCharCode)
{
if (strTwoCharCode.length() != 2)
Expand All @@ -196,6 +241,27 @@ bool CLangCodeExpander::ConvertLinuxToWindowsRegionCodes(const CStdString& strTw
return true;
}

bool CLangCodeExpander::ConvertWindowsToGeneralCharCode(const CStdString& strWindowsCharCode, CStdString& strThreeCharCode)
{
if (strWindowsCharCode.length() != 3)
return false;

CStdString strLower(strWindowsCharCode);
strLower.MakeLower();
for (unsigned int index = 0; index < sizeof(CharCode2To3) / sizeof(CharCode2To3[0]); ++index)
{
if ((CharCode2To3[index].win_id && strLower.Equals(CharCode2To3[index].win_id)) ||
strLower.Equals(CharCode2To3[index].id))
{
strThreeCharCode = CharCode2To3[index].id;
return true;
}
}

return true;
}
#endif

bool CLangCodeExpander::LookupInMap(CStdString& desc, const CStdString& code)
{
STRINGLOOKUPTABLE::iterator it;
Expand Down
8 changes: 7 additions & 1 deletion xbmc/utils/LangCodeExpander.h
Expand Up @@ -34,12 +34,18 @@ class CLangCodeExpander

bool Lookup(CStdString& desc, const CStdString& code);
bool Lookup(CStdString& desc, const int code);
#ifdef _WIN32
#ifdef TARGET_WINDOWS
bool ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode, bool localeHack = false);
bool ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode, bool localeHack = false);
#else
bool ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode);
bool ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode);
#endif

#ifdef TARGET_WINDOWS
bool ConvertLinuxToWindowsRegionCodes(const CStdString& strTwoCharCode, CStdString& strThreeCharCode);
bool ConvertWindowsToGeneralCharCode(const CStdString& strWindowsCharCode, CStdString& strThreeCharCode);
#endif

void LoadUserCodes(const TiXmlElement* pRootElement);
void Clear();
Expand Down

0 comments on commit 7c2ed63

Please sign in to comment.