Make a simple interface class for localizers. Move the theme-based

localizer into ThemeManager.  Use simple MI to hook ThemeMetric::Read
to continue to automatically update when needed.
This commit is contained in:
Glenn Maynard
2006-01-13 00:40:12 +00:00
parent c827c9ec1e
commit 269c6f0ec7
3 changed files with 87 additions and 22 deletions
+31
View File
@@ -52,6 +52,34 @@ static IniFile *g_pIniMetrics;
#include "SubscriptionManager.h"
static SubscriptionManager<IThemeMetric> g_Subscribers;
class LocalizedStringImplThemeMetric : public ILocalizedStringImpl, public ThemeMetric<RString>
{
public:
static ILocalizedStringImpl *Create() { return new LocalizedStringImplThemeMetric; }
void ILocalizedStringImpl::Load( const RString& sGroup, const RString& sName )
{
ThemeMetric<RString>::Load( sGroup, sName );
}
virtual void Read()
{
if( m_sName != "" && THEME && THEME->IsThemeLoaded() )
{
THEME->GetString( m_sGroup, m_sName, m_currentValue );
m_bIsLoaded = true;
}
}
const RString &GetLocalized() const
{
if( IsLoaded() )
return GetValue();
else
return m_sName;
}
};
void ThemeManager::Subscribe( IThemeMetric *p )
{
g_Subscribers.Subscribe( p );
@@ -318,6 +346,9 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt
UpdateLuaGlobals();
}
// Use theme metrics for localization.
LocalizedString::RegisterLocalizer( LocalizedStringImplThemeMetric::Create );
// reload subscribers
if( g_Subscribers.m_pSubscribers )
{