Starts in:
1 DAY
20 HRS
51 MIN
9 SEC
Starts in:
1 D
20 H
51 M
9 S
Open Closed

Localization inside GetListAsExcelFileAsync() method #6667


User avatar
0
icoretchi created
  • ABP Framework version: v8.0.3
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
    • Tiered (for MVC) or Auth Server Separated (for Angular): microservice
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hi,

I am trying to localize the column names of the exported excel file that happend in GetListAsExcelFileAsync() of any generated ApplicationServices. I've noticed that the StringLocalizer L that is inherited from the base ApplicationService is not workig properly in this method for any other language beside the default "en". Any ideas?


9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    ABP internally uses Miniexcel to export Excel file.

    You need to use dynamic column names to support localization https://github.com/mini-software/MiniExcel?tab=readme-ov-file#7-dynamiccolumnattribute

    for example:

    var config = new OpenXmlConfiguration
    {
        DynamicColumns = new DynamicExcelColumn[] { 
            new DynamicExcelColumn("id") {Name = L["Id"]},
            new DynamicExcelColumn("name") {Name = L["Name"]},
            new DynamicExcelColumn("createdate") {Name = L["Createdate"]},
            new DynamicExcelColumn("point") {Name = L["Point"]},
        }
    };
    
  • User Avatar
    0
    icoretchi created

    I know that. You didn't understand the question. The problem is in L, as StringLocalizer. It's not working properly. Try the example that you suggested to localize the colums for different language beside english.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you share some code? I will check it.

  • User Avatar
    0
    icoretchi created

    Once again. Just try the code you have suggested:

    var config = new OpenXmlConfiguration { DynamicColumns = new DynamicExcelColumn[] { new DynamicExcelColumn("id") {Name = L["Id"]}, new DynamicExcelColumn("name") {Name = L["Name"]}, new DynamicExcelColumn("createdate") {Name = L["Createdate"]}, new DynamicExcelColumn("point") {Name = L["Point"]}, } };

    I am doing absolutly the same.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is a problem, You can open the AppService.Extended.cs class to update the LocalizationResource

    We will enhance the suite in the next version, your ticket was refunded.

  • User Avatar
    0
    icoretchi created

    In my context the LocalizationResource is properly assigned for the Application Service and localization for exporting to excel it's not working. And I have to mention that for microservices template all the application services are inherited from the base class which properly assign the LocalizationResource. I think the problem is in this specific method GetListAsExcelFileAsync() how is called from UI (in my case from Blazor). I reiterate again the L, as StringLocalizer is working properly from any method of the ApplicationService, besides the GetListAsExcelFileAsync.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Sorry, I can confirm this issue. we will fix it.

    You can try to update the DownloadAsExcelAsync method. for example:

    private  async Task DownloadAsExcelAsync()
    {
        var token = (await BooksAppService.GetDownloadTokenAsync()).Token;
        var remoteService = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Qa") ??
        await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Default");
        var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;
        if(!currentCulture.IsNullOrEmpty())
        {
            currentCulture = "&culture=" + currentCulture;
        }
        NavigationManager.NavigateTo($"{remoteService?.BaseUrl.EnsureEndsWith('/') ?? string.Empty}api/app/books/as-excel-file?DownloadToken={token}&FilterText={Filter.FilterText}&Name={Filter.Name}&Title={Filter.Title}{currentCulture}", forceLoad: true);
    }
    
  • User Avatar
    0
    icoretchi created

    It's still not working properly.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I could not reproduce the problem

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06