Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Custom Localization Provider


Migration from CMS 11 to 12 #again

I have such entry in web config:

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

and given the documentation there:  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.

Edited, Oct 23, 2023 10:51

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.

Oct 23, 2023 11:01

`AddEmbeddedLocalization` was already there


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

Oct 23, 2023 12:33

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.

Oct 23, 2023 12:43

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.

Oct 23, 2023 13:14

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.

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.