NetcodeHub.Packages.Extensions.Localization 1.0.1

dotnet add package NetcodeHub.Packages.Extensions.Localization --version 1.0.1                
NuGet\Install-Package NetcodeHub.Packages.Extensions.Localization -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetcodeHub.Packages.Extensions.Localization" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetcodeHub.Packages.Extensions.Localization --version 1.0.1                
#r "nuget: NetcodeHub.Packages.Extensions.Localization, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetcodeHub.Packages.Extensions.Localization as a Cake Addin
#addin nuget:?package=NetcodeHub.Packages.Extensions.Localization&version=1.0.1

// Install NetcodeHub.Packages.Extensions.Localization as a Cake Tool
#tool nuget:?package=NetcodeHub.Packages.Extensions.Localization&version=1.0.1                

Install Packages

              NetcodeHub.Packages.Extensions.Localization

Register package

             builder.Services.AddNetcodeHubLocalizationService();

Create your Resource Folder and Files and create your language selection component

         @using NetcodeHub.Packages.Extensions.Localization
         @inject LanguageService LanguageService

         <span class="text-muted" style="margin-left:10px; margin-right:2px">Language</span>
         <select @onchange="ChangeLanguage" class="form-select d-flex align-content-end" 
            placeholder="Sele" style="width:100px">

        <option selected>@SelectedCulture</option>
        @if (SelectedCulture != "en-US")
        {
            <option value="en-US">en-US</option>
        }
        @if (SelectedCulture != "fr-FR")
        {
            <option value="fr-FR">fr-FR</option>
        }
        </select>

    @code {
             string SelectedCulture = "fr-FR";
             private async void ChangeLanguage(ChangeEventArgs e)
             {
            SelectedCulture = e.Value!.ToString()!;
            await LanguageService.ChangeCulture(SelectedCulture);
          }

          protected override async Task OnAfterRenderAsync(bool firstRender) => await GetCulture();

        private async Task GetCulture()
        {
            string culture = (await LanguageService.GetCurrentCulture())!;
            if (culture != null) SelectedCulture = culture;

            StateHasChanged();
        }
    }

Use the component

    <div class="page">
        <div class="sidebar">
            <NavMenu />
        </div>

        <main>
            <div class="top-row px-4">
                <a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
                <BlazorApp.Components.Pages.Language/>
            </div>

            <article class="content px-4">
                @Body
            </article>
        </main>
    </div>

Use the component and subscribe to Notfication Change event

    @code
    {
         @using NetcodeHub.Packages.Extensions.Localization

         @inject IStringLocalizer<AppResource> Localizer

         @inject LanguageService LanguageService

         @implements IDisposable

         @Localizer["Name"]"
         @Localizer["Email"]
         @Localizer["Password"]

         protected override void OnInitialized() => LanguageService.Notify += StateHasChanged;

        protected override async Task OnAfterRenderAsync(bool firstRender) => 
        await LanguageService.LoadCulture(Default: "fr-FR");

        public void Dispose() => LanguageService.Notify -= StateHasChanged;
      }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 328 4/14/2024

NetcodeHub Local Storage package integrated to replace the old one.