Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two errors in version 5.0.3 #406

Closed
lpyedge opened this issue Dec 14, 2023 · 4 comments
Closed

Two errors in version 5.0.3 #406

lpyedge opened this issue Dec 14, 2023 · 4 comments

Comments

@lpyedge
Copy link
Contributor

lpyedge commented Dec 14, 2023

  1. Excel export file is a 0kb file.
  2. The displayed language is based on the system language. The localization code scheme I use cannot display according to the language I set.
  • Version 5.0.3
  • OS: Windows 11 (23H2)
  • Browser Edge (v120)
  • .Net Version 6.0
@lpyedge
Copy link
Contributor Author

lpyedge commented Dec 15, 2023

I believe the Excel error was created by Commit 578d768.
[GridBlazor/ExcelWriter.cs]
Line173 -174
I downgraded to version 4.1.1, and now the Excel export works well.

@gustavnavar
Copy link
Owner

gustavnavar commented Dec 22, 2023

You are right. The issue about excel export is due to disposing the stream. I've published a new version (5.0.4) to fix it.

Referring the displayed language, I understand that the issue happens also in version 4.1.1, doesn't it? Are you using blazor-server or blazor-wasm?

@lpyedge
Copy link
Contributor Author

lpyedge commented Dec 27, 2023

You are right. The issue about excel export is due to disposing the stream. I've published a new version (5.0.4) to fix it.

Referring the displayed language, I understand that the issue happens also in version 4.1.1, doesn't it? Are you using blazor-server or blazor-wasm?

yes, the language displayed error is also happens in version 4.1.1 with blazor-server.

@gustavnavar
Copy link
Owner

You can look at this sample project https://gridblazor.azurewebsites.net/. It is implemented as a blazor-server project.

The source code is here https://github.com/gustavnavar/Grid.Blazor/tree/master/GridBlazorServerSide.

There is a blazor component that configures the language for each session:

@using System.Globalization
@using Microsoft.AspNetCore.Builder
@using Microsoft.Extensions.Options
@inject NavigationManager NavigationManager
@inject IOptions<RequestLocalizationOptions> LocOptions

<select class="form-control" value="@_language" @onchange="SetLanguage">
    @foreach (var culture in LocOptions.Value.SupportedUICultures)
    {
        <option value="@culture.Name">@culture.Name</option>
    }
</select>

@code {
    private string _language;

    protected override void OnInitialized()
    {
        _language = CultureInfo.CurrentCulture.Name;
    }

    private void SetLanguage(ChangeEventArgs e)
    {
        var culture = (string)e.Value;
        var uri = new Uri(NavigationManager.Uri)
            .GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
        var query = $"?culture={Uri.EscapeDataString(culture)}&" +
            $"redirectUri={Uri.EscapeDataString(uri)}";

        NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
    }
}

It calls to a web service that configures a cookie for the language:

using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;

namespace GridBlazorServerSide.Controllers
{
    [Route("[controller]/[action]")]
    public class CultureController : Controller
    {
        public IActionResult SetCulture(string culture, string redirectUri)
        {
            if (culture != null)
            {
                HttpContext.Response.Cookies.Append(
                    CookieRequestCultureProvider.DefaultCookieName,
                    CookieRequestCultureProvider.MakeCookieValue(
                        new RequestCulture(culture)));
            }

            return LocalRedirect(redirectUri);
        }
    }
}

@lpyedge lpyedge closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants