OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.23k stars 2.34k forks source link

Add Blazor WASM Support for OrchardCore.Localization.Core #15543

Open BrunoJuchli opened 3 months ago

BrunoJuchli commented 3 months ago

Is your feature request related to a problem? Please describe.

After installing OrchardCore.Localization.Core into a .net 8 Blazor WASM project I get the following error:

Error NETSDK1082 : There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'

This is due to the <FrameworkReference Include="Microsoft.AspNetCore.App" /> in the csproj.

Without this reference, there is no HtmlLocalizer and also no data annotations localization - these are not supported in Blazor WASM.

Furthermore, the setup in LocalizationServiceCollectionExtensions.AddPortableObjectLocalization doesn't work for Blazor WASM since - as far as I found - it doesn't support local files. So using ContentRootPoFileLocationProvider makes no sense.

Also, for

Describe the solution you'd like

Split the assemblies/ nuget packages so that

Describe alternatives you've considered

Varying on what I've wrote above, the aspect of where is the PO file retrieved from could made pluggable, and a choice of:

could be offered.

Notes

As an experiment, I've removed the `<FrameworkReference Include="Microsoft.AspNetCore.App" /> and all types that fail to compile then. I've also had to plug in a customized ITranslationProvider because so as to load the PO files from the web server (via HttpClient) instead of from a local file (I don't think these are availabel in Blazor WASM - at least i couldn't find a way to include these...). This way I got it working.

hishamco commented 3 months ago

As you know OC started before Blazor was a thing :) we might investigate into Blazor support, especially for Core APIs

/cc @sebastienros @Skrypt

Skrypt commented 3 months ago

You can create a Pull Request with your suggested changes that will be easier to review. Then, also, what @hishamco said. This was not designed with Blazor in mind as it happened after.