简体   繁体   English

B2C:来自 REST API 的消息的本地化

[英]B2C: Localization for messages originating from REST API

I am currently implementing this example to use an rest API during the user registration.我目前正在实施此示例以在用户注册期间使用 rest API。

The basic idea is that the API throws an 409 Conflict error to interrupt the registration.基本思路是API抛出409 Conflict错误来中断注册。

// Can I return a special "StringId" or something here for localization?
return new ConflictObjectResult(new B2CResponseModel($"A verification email sent to you. Please open your mail box and click on the link. If you didn't receive the email, please click on the 'Send verification email' button.", HttpStatusCode.Conflict));

I want to show the user a message that is localized to their current language.我想向用户显示一条本地化为他们当前语言的消息。 I would prefer to do the localization within the custom policies, but I would also accept a solution within the API (would need to get the User Language for this).我更愿意在自定义策略中进行本地化,但我也接受 API 中的解决方案(为此需要获取用户语言)。

Is there a way to do this localization?有没有办法进行这种本地化? Like returning a StringId via API and using this within the policy?喜欢通过 API 返回StringId并在策略中使用它吗?

I am also considering not returning an error from the API, to show the message in a new screen instead (like How to display error returned from custom REST API endpoint in a subsequent orchestration step? ).我还考虑不从 API 返回错误,而是在新屏幕中显示消息(例如如何在后续编排步骤中显示从自定义 REST API 端点返回的错误? )。 However, localization options for this elude me as well.然而,这个的本地化选项也让我望而却步。

Hope this is similar to this希望这与类似

See the answer by Jas Suri .请参阅Jas Suri的回答。 Pass the localisation parameter to API and return the localised message or can return an error code and based on that display translated message using policy itself.将本地化参数传递给 API 并返回本地化消息,或者可以返回错误代码并基于该显示使用策略本身的翻译消息。

In case anybody is looking for a way to send the user's locale to the REST API:如果有人正在寻找将用户的语言环境发送到 REST API 的方法:

https://docs.microsoft.com/nb-no/azure/active-directory-b2c/claim-resolver-overview https://docs.microsoft.com/nb-no/azure/active-directory-b2c/claim-resolver-overview

        <TechnicalProfile Id="REST-API-SendVerificationEmail">
          <DisplayName>Sign-Up send link</DisplayName>
          <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          <Metadata>
            <Item Key="ServiceUrl">https://xxxx</Item>
            <Item Key="AuthenticationType">None</Item>
            <Item Key="SendClaimsIn">Body</Item>
          </Metadata>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="email" />
            <InputClaim ClaimTypeReferenceId="userLanguage" DefaultValue="{Culture:LanguageName}" />
            <InputClaim ClaimTypeReferenceId="policyId" PartnerClaimType="policy" DefaultValue="{Policy:PolicyId}" />
            <InputClaim ClaimTypeReferenceId="scope" DefaultValue="{OIDC:scope}" />
            <InputClaim ClaimTypeReferenceId="clientId" DefaultValue="{OIDC:ClientId}" />
          </InputClaims>
          <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
        </TechnicalProfile>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM