Open Closed

Localization with json or resx? #2414


User avatar
0
z2lai created
  • ABP Framework version: v5.0.1
  • UI type: Blazor Server
  • DB provider: EF Core

The docs show localization examples using json files, however, Telerik UI for Blazor provides localization in resx files. Is it recommended to manually convert these resx files to json to be used in ABP or can we also use resx files for localization in ABP?


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

    Hi,

    ABP can load localized resources from anywhere, you can write localized contributors from resx files。

    Example:

    public class MyVirtualFileLocalizationResourceContributor : VirtualFileLocalizationResourceContributorBase
    {
        public MyVirtualFileLocalizationResourceContributor (string virtualPath)
            : base(virtualPath)
        {
    
        }
    
        protected override bool CanParseFile(IFileInfo file)
        {
            ....
        }
    
        protected override ILocalizationDictionary CreateDictionaryFromFileContent(string jsonString)
        {
            ....
        }
    }
    
    Configure<AbpLocalizationOptions>(options =>
    {
        options
            .Resources
            .Add<DefaultResource>("en").Contributors.Add(new MyVirtualFileLocalizationResourceContributor(...));
    
    });
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11