1

我通过对 XXX_TrustFrameworkExtensions 文件的以下更改实现了本地化。

这个 LocalizedResources 可以外部化吗?任何帮助是极大的赞赏。

<BuildingBlocks>
    <ContentDefinitions>
        <ContentDefinition Id="api.signuporsignin">
            <LocalizedResourcesReferences MergeBehavior="Prepend">
                <LocalizedResourcesReference Language="en-US" LocalizedResourcesReferenceId="en-US"/>
                <LocalizedResourcesReference Language="es-MX" LocalizedResourcesReferenceId="es-MX"/>
            </LocalizedResourcesReferences>
        </ContentDefinition>
    </ContentDefinitions>
    <Localization Enabled="true">
        <SupportedLanguages DefaultLanguage="en-US" MergeBehavior="ReplaceAll">
            <SupportedLanguage>en-US</SupportedLanguage>
            <SupportedLanguage>es-MX</SupportedLanguage>
        </SupportedLanguages>
        <LocalizedResources Id="en-US">
            <LocalizedStrings>
                <LocalizedString ElementType="UxElement" StringId="logonIdentifier_email">#Email Address</LocalizedString>
                <LocalizedString ElementType="UxElement" StringId="password">#Password</LocalizedString>
                <LocalizedString ElementType="UxElement" StringId="email_pattern">^[a-zA-Z0-9.!#$%&amp;'^_`{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$</LocalizedString>
                <LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfInvalidPassword">#Your password is incorrect.</LocalizedString>
                <LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfClaimsPrincipalDoesNotExist">#We can't seem to find your account.</LocalizedString>
            </LocalizedStrings>
        </LocalizedResources>
        <LocalizedResources Id="es-MX">
            <LocalizedStrings>
                <LocalizedString ElementType="UxElement" StringId="logonIdentifier_email">#Correo electrónico</LocalizedString>
                <LocalizedString ElementType="UxElement" StringId="password">#Contraseña</LocalizedString>
                <LocalizedString ElementType="UxElement" StringId="email_pattern">^[a-zA-Z0-9.!#$%&amp;'^_`{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$</LocalizedString>
                <LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfInvalidPassword">#Su contraseña es incorrecta.</LocalizedString>
                <LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfClaimsPrincipalDoesNotExist">#Parece que no podemos encontrar su cuenta.</LocalizedString>
            </LocalizedStrings>
        </LocalizedResources>
    </Localization>
</BuildingBlocks>
4

2 回答 2

0

当前本地化资源无法移动到单独的文件/外部化。

于 2020-10-14T11:01:10.397 回答
0

是的,您可以使用策略文件继承将本地化配置提取到单独的文件中。请参阅自定义策略的继承模型:(https://docs.microsoft.com/en-us/azure/active-directory-b2c/custom-policy-overview#inheritance-model

以下是策略文件继承应该是什么样子的概述:

[`Base` Policy file] (Contains your existing BuildingBlocks/ContentDefinition elements)
  ^
  |
[`Localization` Policy file] (Contains only Localization-specific configuration)
  ^
  |
[`XXX_TrustFrameworkExtensions` Policy file] (The policy file that your Relying Party will reference)

您需要创建一个“本地化”策略文件并让您当前的策略文件 ( XXX_TrustFrameworkExtensions) 继承它。然后,本地化策略文件将需要从您的基本策略文件继承。如果您没有基本策略文件,您应该创建一个并将您的<BuildingBlocks>元素移动到其中。

您需要<BuildingBlocks>在 Base 和 Localization 策略文件中定义一个元素。在您的本地化策略文件中,您可以添加<ContentDefinitions><Localization>元素所需的所有本地化特定设置。当依赖方尝试引用您的主策略文件 ( XXX_TrustFrameworkExtensions) 时,Azure B2C 将合并<BuildingBlocks>来自您的基本策略文件和本地化策略文件的元素内容。

Azure B2C Custom Policy Starter Pack 有一个很好的例子来说明如何实现这一点。请参阅:https ://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack/tree/master/LocalAccounts

例子

Your-Base-Policy.xml

<TrustFrameworkPolicy    
    ...
    PolicyId="Your-Base-Policy"
    ...>  
  <BuildingBlocks>      
    <ContentDefinitions>
      <ContentDefinition Id="api.selfasserted.signinemail">
        ...
      </ContentDefinition>
     ...
    </ContentDefinitions>
  </BuildingBlocks>
  ...
</TrustFrameworkPolicy>

Localization-Policy.xml

<TrustFrameworkPolicy    
    ...
    PolicyId="Localization-Policy"
    ...>
  <BasePolicy>...
    <PolicyId>Your-Base-Policy</PolicyId>
  </BasePolicy>
  <!-- Contains only localization specific elements-->
  <BuildingBlocks>  
    <ContentDefinitions>      
      <ContentDefinition Id="api.selfasserted.signinemail">     
        <LocalizedResourcesReferences MergeBehavior="Append">
            ...          
        </LocalizedResourcesReferences>
    </ContentDefinition>
    <Localization Enabled="true">
        <LocalizedCollections>          
        ...
        </LocalizedCollections>
        <LocalizedStrings>
        ...
        </LocalizedStrings>
      </Localization>
    </ContentDefinitions>
  </BuildingBlocks>
  ...
</TrustFrameworkPolicy>

XXX_TrustFrameworkExtensions.xml

<TrustFrameworkPolicy    
    ...
    PolicyId="XXX_TrustFrameworkExtensions"
    ...>
 <BasePolicy>...
    <PolicyId>Localization-Policy</PolicyId>
  </BasePolicy>
  ...
</TrustFrameworkPolicy>
于 2022-01-06T07:24:31.537 回答