hishamco / hishambinateya.com

Hisham's Blog
http://www.hishambinateya.com/
2 stars 1 forks source link

Make PO files ❤️ Localization in ASP.NET Core 2.0 using Orchard Core #48

Open hishamco opened 5 years ago

nyghtrocker commented 5 years ago

Hi how can i override ContentRootPoFileLocationProvider and replace using dependency injection. I’m using orchard core as nuget package and tring to override po files location . Is any difference between content root po file location provider and ModularPoFileLocationProvider?

hishamco commented 5 years ago

Things are change since I wrote my blog post, but let me check or forward your question there ..

hishamco commented 5 years ago

According to the Orchard Core docs PO files are found via the following steps:

So you can simply override the ContentRootPoFileLocationProvider by injecting your CustomContentRootPoFileLocationProvider into DI as the following:

services.AddSingleton<ILocalizationFileLocationProvider, CustomContentRootPoFileLocationProvider>()
nyghtrocker commented 5 years ago

In startup.cs I have like this: services.AddOrchardCms().AddSingleton<ILocalizationFileLocationProvider, MyLIModularPoFileLocationProvider>(); and then I have

public class  MyLIModularPoFileLocationProvider : ILocalizationFileLocationProvider
{
        public MyLIModularPoFileLocationProvider(IOptions<LocalizationOptions> localizationOptions )
        {
            _resourcesContainer = localizationOptions.Value.ResourcesPath; // Localization
        }
        public IEnumerable<IFileInfo> GetLocations(string cultureName)
        {

        }
}

breakpoint hit in constructor but my breakpoint never hit on GetLocations(string cultureName) method. Do you know what should I do? I also tried with services.Replace(ServiceDescriptor.Singleton<ILocalizationFileLocationProvider, MyLIModularPoFileLocationProvider>());

hishamco commented 5 years ago

While the topic go further I think we need to move this to Orchard Core repo for better tracking and involve the community