November Happy Hour will be moved to Thursday December 5th.

Custom Localization Provider

Vote:
 

Migration from CMS 11 to 12 #again

I have such entry in web config:

    <localization>
      <providers>
        <add virtualPath="~/lang" name="languageFiles"
          type="EPiServer.Framework.Localization.XmlResources.FileXmlLocalizationProvider, EPiServer.Framework.AspNet"/>
        <add name="inriverTranslations" type="Etac.Business.Localization.InRiverLocalizationProvider, Sth"/>
      </providers>
    </localization>

and given the documentation there: https://docs.developers.optimizely.com/content-management-system/docs/configuring-a-custom-localization-provider  I've created a startup code:

services.AddLocalizationProvider<InRiverLocalizationProvider, NameValueCollection>(
                o =>
                {
                    o[FileXmlLocalizationProvider.VirtualPathKey] = @"~/lang";
                })

but I can't make it work with any different variations of that code above. The app go throug that config (checked on debug) and later doesn't start running :/ 


The custom localizer relevant code:

 public class InRiverLocalizationProvider : LocalizationProvider
    {
        public override IEnumerable<ResourceItem> GetAllStrings(string originalKey, string[] normalizedKey, CultureInfo culture)
        {
            //DO STH
            return LOCALIZED STRING
        }

        public override string GetString(string originalKey, string[] normalizedKey, CultureInfo culture)
        {
           //DO STH
            return LOCALIZED STRING
        }
    }


That localizer obv works in the CMS11 solution, but I am struggling to configure that on CMS12, hence the question.

#311303
Edited, Oct 23, 2023 10:51
Vote:
 

I see that in CMS 11 config you have two providers - InRiver and XML. Do you use the same in CMS 12? If yes - order of provider registrations is important, and most probably you want to use the one from Optimizely (services.AddEmbeddedLocalization<Startup>() or similar) as the last one.

#311304
Oct 23, 2023 11:01
Vote:
 

`AddEmbeddedLocalization` was already there

            .AddLocalizationProvider<InRiverLocalizationProvider>()
            .AddEmbeddedLocalization<Startup>()

so I added the InRiverLocalizationProvider, and the "fun" thing is, that the app is not starting with that single row added :/ 

#311315
Oct 23, 2023 12:33
Vote:
 

If the app is not starting - that means there's some kind of exception in console, and application aborted? Do you have it to share here?

Without provider sources we can only guess what exactly fails, but most probably container cannot create provider in some way.

#311316
Oct 23, 2023 12:43
Vote:
 

Thats the point, I can't see antything in console :/ Will try to debug the Startup, maybe indeed there is some issue with the provider.

#311319
Oct 23, 2023 13:14
Vote:
 

Works now all fine :) 
Thanks for tip for ordering that, I know that it matters but usually forget about that :D 

The issue was that the custom LocalizationProvider had some services to resolve in ctor, which failed miserably while `Run()` was invoked on a webhost (build was fine), even the services were registered before "AddLocalizationProvider...".  Reworked the provider, so the services are resolved _on the go_, and no more issues with that.

#311391
Oct 24, 2023 11:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.