Starts in:
0 DAY
17 HRS
50 MIN
11 SEC
Starts in:
0 D
17 H
50 M
11 S
Open Closed

Localiztion of POCO classes on Blazor #1146


User avatar
0
smutairi created
  • ABP Framework version: v4.3.0 RC1
  • UI type: Blazor
  • DB provider: EF Core

I am trying to localize Validation Messages for POCO (DTO) classes on Blazor.

I have my own Resource added and is working fine on notifications and other strings. but I want to localize the <ValidationError> tags on Razor pages

Example DTO


public class StockTypeCreateDto
    {
     ----ADD IT HERE---
        [Required]
        [StringLength(StockTypeConsts.NameMaxLength)]
        public string Name { get; set; }
        [Required]
        public bool IsStatic { get; set; }
    }
}

Example Razor

                <Validation>
                        <Field>
                            <FieldLabel>@L["Label:Name"] *</FieldLabel>
                            <TextEdit Autofocus="true" @bind-Text="@NewStockType.Name" MaxLength="StockTypeConsts.NameMaxLength">
                                <Feedback>
                                ----ADD IT HERE---
                                    <ValidationError>@L[MyProjectErrorCodes.RequiredField, L["Label:Name"]]</ValidationError>
                                </Feedback>
                            </TextEdit>
                        </Field>
                    </Validation>

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

    Hi,

    Can you explain in detail and provide steps? thanks.

  • User Avatar
    0
    smutairi created

    Hi,

    Can you explain in detail and provide steps? thanks.

    I would like to have the Validation Errors localized.

    I am sure it can be done using Data Annotations, but I want to use the ABP way of using the class xxxxErrorCodes and my MappedCodeNamespace for Exceptions localizations in the *.json file

  • User Avatar
    0
    mladen.macanovic created

    Hi,

    I'm not sure if I understand correctly what you want to accomplish. But I think all you have to do is to add additional key/value translations into the .json file. And then use those keys to read read translation, eg @L["TranslationName"].

  • User Avatar
    0
    smutairi created

    Hi,

    I'm not sure if I understand correctly what you want to accomplish. But I think all you have to do is to add additional key/value translations into the .json file. And then use those keys to read read translation, eg @L["TranslationName"].

    Hi,

    I would like to localize the [Required(ErrorMessage='')]

  • User Avatar
    -1
    mladen.macanovic created

    It should work with localization handler helper.ErrorMessage is automatically used by the localizer if it is provided and given the same key it is also located in the .json file it should work.

    First you need to inject the handler

    @inject AbpBlazorMessageLocalizerHelper<IdentityResource> LH
    

    Next you just define it on Validation

    <Validation MessageLocalizer="@LH.Localize">
        <Field>
            <FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
            <TextEdit @bind-Text="EditingEntity.UserName">
                <Feedback>
                    <ValidationError/>
                </Feedback>
            </TextEdit>
        </Field>
    </Validation>
    
  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

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