【问题标题】:Localization of 'requiredField' on a claim type in a custom Azure B2C policy自定义 Azure B2C 策略中声明类型的“requiredField”本地化
【发布时间】:2020-07-01 08:52:34
【问题描述】:

我有一个自定义 Azure B2C 策略,其中包含在注册中使用的以下声明:

...
  <ClaimType Id="givenName">
    <DisplayName>First Name</DisplayName>
    <DataType>string</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" 
        PartnerClaimType="given_name" />
      <Protocol Name="OpenIdConnect" 
        PartnerClaimType="given_name" />
      <Protocol Name="SAML2" 
        PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" />
    </DefaultPartnerClaimTypes>
    <UserHelpText>Your given name (also known as first name).</UserHelpText>
    <UserInputType>TextBox</UserInputType>
  </ClaimType>
...

我希望能够本地化当用户未输入值并尝试继续时出现的错误消息。

这是当前默认/使用本地化元素的“required_field”。 但是,还有许多其他类似的声明,即姓氏,我希望为每个声明显示不同的消息。 即“名是必需的”、“姓是必需的”等;而不仅仅是针对所有声明“需要此信息”的通用消息。

此文档https://docs.microsoft.com/en-us/azure/active-directory-b2c/localization-string-ids 显示了可用的各种 id,但我还是看不到要完成此操作?

这是本地化当前的样子

...
      <LocalizedResources Id="api.localaccountsignup.en">
    <LocalizedStrings>
      <!-- Header -->
      <LocalizedString ElementType="UxElement" StringId="initial_intro">Create a account to start</LocalizedString>
      <!-- First name -->
      <LocalizedString ElementType="ClaimType" ElementId="givenName" StringId="DisplayName">First name</LocalizedString>
      <LocalizedString ElementType="ClaimType" ElementId="givenName" StringId="UserHelpText"></LocalizedString>
      <LocalizedString ElementType="ClaimType" ElementId="givenName" StringId="PatternHelpText">First name is required.</LocalizedString>
      <!-- Last name -->
      <LocalizedString ElementType="ClaimType" ElementId="surname" StringId="DisplayName">Last name</LocalizedString>
      <LocalizedString ElementType="ClaimType" ElementId="surname" StringId="UserHelpText"></LocalizedString>     
      <LocalizedString ElementType="ClaimType" ElementId="surname" StringId="PatternHelpText"></LocalizedString>     
...
      <LocalizedString ElementType="UxElement" StringId="required_field">This information is required.</LocalizedString>
...

我可以看到本地化帮助文本和模式(用于限制)的方法,但当用户根本没有输入任何内容时,什么都没有。

感谢您的帮助!

【问题讨论】:

  • 我已与 AAD 团队取得联系,并会回复您。
  • @AlfredoR 对此有任何更新,我也有类似情况stackoverflow.com/questions/68387341/…
  • @noelor,您的问题解决了吗,如果是,请分享详细信息
  • @AlfredoR 对不起,我从来没有回答过,因为我从来没有真正得到过答案!

标签: localization azure-ad-b2c


【解决方案1】:

我从来没有真正解决过这个问题,因为我认为没有解决方案。至少当时没有(2020 年 7 月)

相反,我不得不解决这个问题。 我所做的是,由于 B2C 允许包含静态 HTML,因此我向该页面添加了自定义 Javascript,以添加所需的额外消息。我保持简单,只是根据声明名称使用 JQuery。

sn-p 下面

function build() {
    addValdationInput('signInName', 'Email address is required', function validiateInput(e) {
        var value = e.target.value;
        const error = document.getElementById('signInName');
        
        if(isEmpty(value)) {
            error.style.visibility = "visible";
            e.target.style.borderColor = "#bb191c";         
            $('#signInName')).html('Email address is required' + svgItemLevelErrorIconHtml());
        } else if(!isValidEmail(value)) {
            error.style.visibility = "visible";
            e.target.style.borderColor  = "#bb191c";
            $('#signInName')).html('Email address is required' + svgItemLevelErrorIconHtml());
        } else {
            e.target.value = value.trim();
            Controller.hideValidationError(error,e);    
        }
    });
  
  // ...
}
// ...
export function svgItemLevelErrorIconHtml() {
  return '<svg class=...';
}
export function addValdationInput(id, errorText, validationAction) {
    $('#' + id).after(buildValidationHtml(id,errorText));   
    $("#" + id).blur(validationAction);
}
export function buildValidationHtml(id, errorText) {
    var content = '<div id=';
    content += getErrorID(id);
    content += ' class="b2c-error" style="visibility: hidden;">';
    content += svgItemLevelErrorIconHtml();
    content += errorText;
    content += '</div>';
    return content;
}

我知道这不是最好的,因为这意味着我现在需要存储 i18n 字符串的地方,但我找不到替代方案。

【讨论】:

    猜你喜欢
    • 2018-12-07
    • 2022-01-10
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2022-11-05
    • 1970-01-01
    相关资源
    最近更新 更多