/*
  File: include/ioutils/Interface_Language.h
  Description: Language system for internationalization/localization
  Part of the Mantis project
  (c) 2002 Lycos Inc.
  Author(s): Andrew McCann & Nicholas Vinen

  This file is distributed for the sole purpose of allowing you to write
  software to interface with Sonique 2 and other Mantis programs. It is
  not to be modified or used for any other purpose without written
  authorization.

  If you redistribute this file, it must be in the original package
  complete with all other files provided, including the usage agreement.

  Do not remove this notice.
*/

#ifndef _INTERFACE_LANGUAGE_H_
#define _INTERFACE_LANGUAGE_H_

#ifdef DEBUG_INCLUDE_ORDER
#pragma message("Including " __FILE__ "\n" )
#endif


#if _MSC_VER > 1000
#pragma once
#endif

#include "mgeneric.h"
#include "charstring.h"
#include "HeapPtr.h"

// {5D8CDFDA-6CEA-4cc3-8457-B3E97FC9DF9E}
DEFINE_MID( MID_LANGUAGE_TRANSLATOR, 0x5d8cdfda, 0x6cea, 0x4cc3, 0x84, 0x57, 0xb3, 0xe9, 0x7f, 0xc9, 0xdf, 0x9e);

class MTranslator : public MGeneric
{
public:
	virtual WString			__stdcall	Get( const char* str ) const										= 0;
	virtual WString			__stdcall	GetFontFace(const wchar_t* Type)									= 0;
	virtual uint32			__stdcall	GetFontSize(const wchar_t* Type)									= 0;
	virtual bool			__stdcall	GetSubSection( const char* szName, RefPtr<MTranslator>& toHere)		= 0;	

};

class MLanguageTranslator : public MGeneric
{
public:
	virtual bool			__stdcall	GetTranslator( const wchar_t* wcModule, const wchar_t* wcDefaultLang, RefPtr<MTranslator> &ToHere)	const	= 0;
	virtual int32			__stdcall	GetAllLanguages(  const wchar_t* wcModule, Array<WString>& wsaLanguages ) const						= 0;
	virtual bool			__stdcall	SetLanguagePrioritys( Array<WString>& wsaLanguages )												= 0;
	virtual int32			__stdcall	GetLanguagePrioritys( Array<WString>& wsaLanguages ) const											= 0;
	
	virtual int32			__stdcall	AddLanguageResource( const wchar_t* wcResPath, const char* szResName )								= 0;
	virtual int32			__stdcall	RemoveLanguageResource( const wchar_t* wcResPath, const char* szResName )							= 0;
};


enum
{
	ERR_LANG_NOSUCHLANGUAGE,
	ERR_LANG__NUM
};

inline MError* GetLanguageErrors(MError* Errors)
{
	Errors[ERR_LANG_NOSUCHLANGUAGE].Name =	"no such error found in current language database";

	return Errors;
}



EXTERN_C const MID FID_IOUTILS;
inline WString TranslateString(WString wsInput)
{
	if (wsInput.CompareTo(L"lang://", false, 7))
		return wsInput;
	uint32 pos = 7;
	while (wsInput[pos] && wsInput[pos] != '/')
		pos++;
	if (!wsInput[pos] || pos == 7)
		return wsInput;
	WString wsModule = wsInput.SubString(7, pos-7);
	WString wsKey = wsInput.SubString(pos + 1);
	HeapMidPtr< MLanguageTranslator,		&FID_IOUTILS,	&MID_LANGUAGE_TRANSLATOR, true	> pLanguages;
	RefPtr<MTranslator> pTrans;
	pLanguages->GetTranslator(wsModule, L"english", pTrans);
	if (pTrans)
		return pTrans->Get(AString(wsKey));
	else 
		return wsInput;
}
#define ERR_LANG__MODULE "Language Services"


#endif
