Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Language and In...Language and In...Custom LocalizationProviderCustom LocalizationProvider
Previous
 
Next
New Post
6/27/2012 4:07 AM
 
Robert

I am happy to do as you suggest. I am not a DNN 6.2 source code maestro, so it would cut down the time to this by hours (or more) if you could point to where I should do this?

At the moment I am looking at the Application_Start on DotNetNukeHttpApplication and trying to work out how to add the right element to web.config. Any pointers you have would be gratefully recieved.

Neil
 
New Post
6/27/2012 3:59 PM
 

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?

 
New Post
6/27/2012 7:09 PM
 
it looks correct on first glance - i dont have time to dive into the code to verify but suggest you log it as a bug to support.dotnetnuke.com and ensure you check the "includes code fix" checkbox so we will review it in a reasonable amount of time (we have many bugs/enhancements and have to priortise - we use severity, priority and whether something has a code fix to do so)

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
6/28/2012 2:40 AM
 

Thanks. I'll do that but before I do, I want to understand the class definition of LocalizationProvider as I am not too familiar with DI containers:

public class LocalizationProvider : ComponentBase<ILocalizationProvider, LocalizationProvider>, ILocalizationProvider

As well as implementing the ILocalizationProvider, this class seems to inherit from whatever the container delivers. But that looks like itself! Clearly I don't know what I am doing here so I don't want to submit code until I do.

Is there anything you can point me to that will me understand that line better? or is it simpler that I think?

 
New Post
6/28/2012 3:29 PM
 
it's dependency injection where a class based on an interface (in this case ILocalizationProvider) is used to inject the dependency (the concrete class - in this case LocalizationProvider) -the code then operates against the interface specification. This allows for the concrete class to be changed - and AFAIR the ComponentBase also does some checking to ensure only a single copy (singleton) is used. This means that we can much easier swap out components - which is particuarlarly useful when we unit test as we can use Mocks in place of core classes (which may have dependancies on other areas such as httpcontext) - see http://en.wikipedia.org/wiki/Dependency_injection for more background

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Language and In...Language and In...Custom LocalizationProviderCustom LocalizationProvider


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out