// Author:	Lizhaowu

#include "stdafx.h"
#include <locale.h>
#include "Localization.h"
#include "HashCalc.h"


#define LANGID_ZH_CN MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED)
//#define LANGID_ZH_TW MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL)
#define LANGID_EN_US MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT)

typedef struct SLanguage {
	LANGID lid;
	LPCTSTR name;
} SLanguage;

static SLanguage _langs[]={
	{LANGID_EN_US,	_T("English")},
	{LANGID_ZH_CN,	_T("chs")},
	//{LANGID_ZH_TW,	_T("cht")},
	{0, NULL}
};

CString GetResString(UINT uStringID, WORD wLangID)
{
	CString resString;
	resString.LoadString(GetModuleHandle(NULL), uStringID, wLangID);
	if (resString.IsEmpty())
		resString.LoadString(GetModuleHandle(NULL), uStringID, LANGID_EN_US);
	return resString;
}

CString GetResString(UINT uStringID)
{
	return GetResString(uStringID,theApp.GetLang());
}

CString GetLangName(LANGID lid)
{
	TCHAR szLang[128];
	GetLocaleInfo(lid, LOCALE_SLANGUAGE, szLang, ARRSIZE(szLang));
	return CString(szLang);
}

bool IsLangSupported(LANGID lid)
{
	SLanguage* pLangs = _langs;
	while (pLangs->lid) {
		if (pLangs->lid == lid)
			return true;
		pLangs++;
	}
	return false;
}

void MakeLangSelection(CComboBox& combo)
{
	combo.ResetContent();
	SLanguage* pLangs = _langs;
	while (pLangs->lid) {
		int i = combo.AddString(GetLangName(pLangs->lid));
		combo.SetItemData(i,pLangs->lid);
		if (theApp.GetLang() == pLangs->lid)
			combo.SetCurSel(i);
		pLangs++;
	}
}
