Starts in:
0 DAY
19 HRS
3 MIN
26 SEC
Starts in:
0 D
19 H
3 M
26 S
Open Closed

Localization resource does not load custom localization file in production after upgrade from 6.x to 7.0.2 #4650


User avatar
0
bma.ffm.dev@sjrb.ca created
  • ABP Framework version: v7.0.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: N/A
  • Steps to reproduce the issue:"

We took an existing application using ABP 6.8 and upgraded it to 7.x. The application works fine, except that our custom localization strings are not returned in production, only in development. Here are a few details that might be important about our configuration:

In App.Domain.Shared, I created custom localization files en.json and fr.json files in directory /Localization/Auth. In App.AuthDomainSharedModule I created this override to add my AuthResource. I also added the virtualjson path containing the localization files.

    {
        Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<AuthDomainSharedModule>();
        });

        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Add<AuthResource>("en")
                .AddBaseTypes(typeof(AbpValidationResource))
                .AddVirtualJson("/Localization/Auth");
            
            options.DefaultResourceType = typeof(AuthResource);
        });

        Configure<AbpExceptionLocalizationOptions>(options =>
        {
            options.MapCodeNamespace("Auth", typeof(AuthResource));
        });
    }

My AuthResource looks like:

public class AuthResource
{

}

Now, if I change ASPNETCORE_ENVIRONMENT in launchsettings to "Production"

"environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Production"
},

In production, the AuthWebModule will not replace the embeded with physical filesets. It should use the VirtualJson configured with the resource from ConfigureServices above, but it does not seem to be working.

private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment)
    {
        Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<AuthWebModule>();

            if (hostingEnvironment.IsDevelopment())
            {
                 options.FileSets.ReplaceEmbeddedByPhysical<AuthDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, PATH_TO_Auth.Domain.Shared, Path.DirectorySeparatorChar)));
                
                // more like above but removed for brevity
            }
        });
    }

Run the application and make the following request: https://localhost:43311/api/abp/application-configuration?includeLocalizationResources=true

The custom localization strings are not returned. This exact same code did work in 6.x, but is broken since we upgraded to 7.x. Please advise.

Cheers! Trevor


1 Answer(s)
  • User Avatar
    0
    bma.ffm.dev@sjrb.ca created

    We resolved this issue by adding the following to Auth.Domain.Shared.csproj

    <ItemGroup> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="7.0.3" /> </ItemGroup>

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