Open Closed

Localiztion of POCO classes on Blazor #1146


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>

5 Answer(s)
  • 0
    liangshiwei created
    Support Team

    Hi,

    Can you explain in detail and provide steps? thanks.

  • 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

  • 0
    mladen.macanovic created
    Support Team

    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"].

  • 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='')]

  • 0
    mladen.macanovic created
    Support Team

    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>