jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
246 stars 23 forks source link

HostingModel.IsWasm working incorrectly #33

Closed IonRobu closed 4 years ago

IonRobu commented 4 years ago

Hello,

I migrated to .Net 5 preview 7 and your package does not work correctly anymore. After getting the code and making some debugging, I discovered the problem is here:

internal static class HostingModel
    {
        public static readonly bool IsWasm = RuntimeInformation.OSDescription == "web";
    }

OSDescription does not return "web" anymore for wasm, but "Browser" - this generates an error on client app startup. Even you do not intend to update too soon to .Net 5, it would be great if you can change the Wasm detection mode (eventually, to be parameterized), as that mode is not recommended by Microsoft and does not work correctly:

"Most use cases for RuntimeEnvironment.OperatingSystem and RuntimeEnvironment.OperatingSystemVersion are for display purposes, for example, displaying to a user, logging, and telemetry. It's not recommended to make run-time decisions based on an operating system (OS) version. Environment.OSVersion now returns the correct version for Windows and macOS operating systems. However, for most Unix distributions, what is considered to be the "OS version" is not as straightforward. For example, it could be the Linux kernel version, or it could be the distro version. For most Unix platforms, Environment.OSVersion and RuntimeInformation.OSDescription return the version that's returned by uname. To get the Linux distro name and version information, the recommended approach is to read the /etc/os-release file."

https://docs.microsoft.com/en-us/dotnet/core/compatibility/3.1-5.0

jsakamoto commented 4 years ago

@IonRobu Thank you for notify me!

I'll try to fix this problem.

jsakamoto commented 4 years ago

@IonRobu I published new version of this package.

If you want to customize wasm detection code, you can do it by configure I18nTextOptions.IsWasm property.

Please try it out! 😄

IonRobu commented 4 years ago

@jsakamoto , it worked! Thanks!

public static void AddI18n(this IServiceCollection services)
{
    static void opts(I18nTextOptions opts)
    {
        opts.IsWasm = () => true;
        ...
    }
    services.AddI18nText(opts);
}