Open Closed

How to use Language Management Module #5754


User avatar
0
shaynevanasperen@gmail.com created
  • ABP Framework version: v7.3.2
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

I'd like to understand more about the language management module in ABP Commerical. I was under the impression that by using this module, I would not have to create and maintain all the language texts in JSON files. When I add some new UI which needs localization text (without specifying the values in the JSON files), then I can't see that text shown in the language texts screen, regardless of which Resource Name I am filtering by.

So I have three questions:

  1. Do I really need to define all the language texts in JSON files, and if so, can I just leave the values blank so that they can rather be defined throught the user interface and stored in the database?
  2. If I define a localization text in the JSON file and then it is updated using the language management module, how does the framework know which source to use (JSON or database)?
  3. Is there a way for me to define these localization texts in a more strongly-typed way using C# instead of JSON?

4 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi shaynevanasperen,

    1. Yes you need to define all the language texts in JSON file, then only it will be available in language management module UI. Yes you can leave the text blank in JSON so that you can add Target Culture Value from UI.
    2. The framework will take the updated value that is saved from UI.
    3. As if now framework is handling data from JSON, but you can handle that texts as blank in JSON and can be updated from UI.
  • User Avatar
    0
    lizhaofeng created

    You can actually add language texts through the following methods without the need to add them in JSON.

    However, it is still hoped that abp can be provided for adding them from the frontend UI.

      var text = (await LanguageTextRepository.GetListAsync()).FirstOrDefault(l =>
                    l.CultureName == input.CultureName && l.ResourceName == input.ResourceName &&
                    l.Name == input.Name);
    
                if (text == null)
                {
                    await LanguageTextRepository.InsertAsync(
                        new LanguageText(GuidGenerator.Create(), input.ResourceName, input.CultureName, input.Name, input.Value, CurrentTenant?.Id)
                    );
                }
                else
                {
                    text.Value = input.Value;
                    await LanguageTextRepository.UpdateAsync(text);
                }
    
  • User Avatar
    0
    shaynevanasperen@gmail.com created

    Okay, thanks. I was hoping that there would be a way for me to avoid "magic" strings in my code. For example, I would rather write this:

    L[MyApplicationResource.Companies.ConfirmDelete] which relies on nested static classes with const string properties,

    than this:

    L["Companies:ConfirmDelete"] which relies on the same "magic" string appearing in my localization JSON files.

    Can somebody whos is resonsible for the commercial modules architecture/design tell me how they intend to avoid the problem of "magic" strings? A large application could easily accumulate lots of bugs over time without a way to make the localization more strongly typed. Can this be made into an official feature request?

  • User Avatar
    0
    alper created
    Support Team Director

    @enis could you help

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15