Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew 52 posts 234 karma points
    Jun 16, 2021 @ 16:12
    Andrew
    0

    Umbraco 9 : How do I localize register models and/or use translations efficiently

    I added the Register Member partial view snippet and was able to register user using beta 3.

    I looked at the view to see about translating the labels and I'm not sure how to proceed.

    The view uses label-for:

    <label asp-for="@registerModel.Email" class="form-label"></label>
    

    I looked at the Email property and saw that there is display attribute : [Display(Name = "Email")]

    Is there an Umbraco way to override the hard-coded attribute or will I need to put a value into the label myself? eg:

    <label asp-for="@registerModel.Email" class="form-label">@myEmailTranslation</label>
    

    If so, is there a simpler path to get translations than what I've tried

    @inject Umbraco.Cms.Core.Services.ILocalizationService localization;
    @{
        var dItemRoot = localization.GetDictionaryItemByKey("RegisterModel");
        var dItems = localization.GetDictionaryItemChildren(dItemRoot.Key).ToDictionary(x=>x.ItemKey);
        var currentLangauge = 1;//??
        var dItem = dItems["Email"].GetTranslatedValue(currentLangauge);
    }
    
  • Andrew 52 posts 234 karma points
    Feb 10, 2022 @ 20:53
    Andrew
    0

    I eventually found Umbraco helper's GetDictionaryValue to get the translation value

    @inject Umbraco.Cms.Web.Common.UmbracoHelper myhelper
    @myhelper.GetDictionaryValue(the Key)
    

    However I've come back to this issue because I still haven't found an answer for the localization of the register and login forms.

    I followed this guide to add the 2 forms: https://our.umbraco.com/Documentation/Tutorials/Members-Registration-And-Logins/

Please Sign in or register to post replies

Write your reply to:

Draft