Good idea so I have had a go. It would be great if you could help me through getting this submitted if you have the experience to help?
I modified web.config:
<section name="localization" requirePermission="false" type="DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke"/>
Then later in the dotnetnuke section added:
<localization defaultProvider="LocalizationProvider">
<providers>
<clear/>
<add name="LocalizationProvider" type="DotNetNuke.Services.Localization.LocalizationProvider, DotNetNuke" providerPath="~\Library\Services\Localization\LocalizationProvider\"/>
</providers>
</localization>
Then in DotNetNukeHttpApplication:
ComponentFactory.InstallComponents(new ProviderInstaller("localization", typeof(ILocalizationProvider)));
I didn't touch the LocalizationProvider as I didn't grock what this does:
public class LocalizationProvider : ComponentBase<ILocalizationProvider, LocalizationProvider>, ILocalizationProvider
Finally I created a ILocalzationProvider that simply wraps the original:
public class CustomLocalizationProvider : ILocalizationProvider
{
private readonly ILocalizationProvider localizationProvider;
public CustomLocalizationProvider()
{
localizationProvider = new LocalizationProvider();
}
#region ILocalizationProvider Members
public string GetString(string key, string resourceFileRoot)
{
return localizationProvider.GetString(key, resourceFileRoot);
}
public string GetString(string key, string resourceFileRoot, string language)
{
return localizationProvider.GetString(key, resourceFileRoot, language);
}
public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings)
{
return localizationProvider.GetString(key, resourceFileRoot, language, portalSettings);
}
public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings,
bool disableShowMissingKeys)
{
return localizationProvider.GetString(key, resourceFileRoot, language, portalSettings,
disableShowMissingKeys);
}
#endregion
}
Then to test I setup the config to use it:
<localization defaultProvider="CustomLocalizationProvider">
<providers>
<clear/>
<add name="LocalizationProvider" type="DotNetNuke.Services.Localization.LocalizationProvider, DotNetNuke" providerPath="~\Library\Services\Localization\LocalizationProvider\"/>
<add name="CustomLocalizationProvider" type="MyCompany.Services.Localization.CustomLocalizationProvider, Enhesa.Services.Localization"/>
</providers>
</localization>
Then I ran the website in debug and low and behold I found my CustomLocalizationProvider was indeed intercepting all the GetString() methods.
Is there something I missed? It felt a bit too easy:-) I wondered if the LocalizationProvider should be moved to a providers folder?