将Azure B2C TrustFrameworkLocalization.xml文件提取到不同的文件中。

huangapple go评论55阅读模式
英文:

Azure B2C TrustFrameworkLocalization.xml extract into different files

问题

我有一个名为TrustFrameworkLocalization.xml的文件,目前包含了两种语言,英语和德语。类似如下内容:

<LocalizedResources Id="api.localaccountsignup.en">
    <LocalizedStrings>
        <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">Email Address</LocalizedString>
        <!-- 其他很多内容 -->
    </LocalizedStrings>
</LocalizedResources>

<LocalizedResources Id="api.localaccountsignup.de">
    <LocalizedStrings>
        <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">E-Mail Adresse</LocalizedString>
        <!-- 其他很多内容 -->
    </LocalizedStrings>
</LocalizedResources>

目前这个文件可以正常工作!但是我的客户希望扩展语言支持,并添加其他12种语言。这将使文件变得非常庞大,可能不容易维护。有没有办法将其拆分成不同的文件?

英文:

I have TrustFrameworkLocalization.xml file, that has for now 2 languages en and de. Something like this:

<LocalizedResources Id="api.localaccountsignup.en">
    <LocalizedStrings>
        <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">Email Address</LocalizedString>
        <!-- many others -->
    </LocalizedStrings>
</LocalizedResources>

<LocalizedResources Id="api.localaccountsignup.de">
    <LocalizedStrings>
        <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">E-Mail Adresse</LocalizedString>
        <!-- many others -->
    </LocalizedStrings>
</LocalizedResources>

It works all file! So far file contains 167 rows, which is maintainable. But my client wants to extent language support and add 12 more languages. Which will make file huge and probably not easily maintainable. Is there any way to split it into different files?

答案1

得分: 1

策略层次结构

是的,您可以设置自定义策略,使它们继承自另一个自定义策略,创建一个链或层次结构。

假设您有一个名为 B2C_1A_Base 的自定义策略,其中包含所有技术配置文件和用户流程,以及一个名为 B2C_1A_SignUpSignIn 的自定义策略,其中包含执行注册/登录流程的依赖方定义。您可以在它们之间插入策略,例如,可以每种语言一个策略,例如:

B2C_1A_Base - 定义在所有子策略中使用的所有内容。

<TrustFrameworkPolicy
   xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="https://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
   PolicySchemaVersion="0.3.0.0"
   TenantId="yourtenant.onmicrosoft.com"
   PolicyId="B2C_1A_Base"
   PublicPolicyUri="http://yourtenant.onmicrosoft.com/B2C_1A_Base">

  <!-- 技术配置文件等 -->

</TrustFrameworkPolicy>

B2C_1A_Translations_En - 继承自 B2C_1A_Base,覆盖了 api.localaccountsignup.en 的本地化内容。

<TrustFrameworkPolicy
   xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="https://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
   PolicySchemaVersion="0.3.0.0"
   TenantId="yourtenant.onmicrosoft.com"
   PolicyId="B2C_1A_Translations_En"
   PublicPolicyUri="http://yourtenant.onmicrosoft.com/B2C_1A_Translations_En">

  <BasePolicy>
    <TenantId>yourtenant.onmicrosoft.com</TenantId>
    <PolicyId>B2C_1A_Base</PolicyId>
  </BasePolicy>

  <LocalizedResources Id="api.localaccountsignup.en">
    <LocalizedStrings>
      <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">Email Address</LocalizedString>
      <!-- 其他内容 -->
    </LocalizedStrings>
  </LocalizedResources>

</TrustFrameworkPolicy>

B2C_1A_Translations_De - 继承自 B2C_1A_Translations_En,覆盖了 api.localaccountsignup.de 的本地化内容。

<TrustFrameworkPolicy
   xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="https://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
   PolicySchemaVersion="0.3.0.0"
   TenantId="yourtenant.onmicrosoft.com"
   PolicyId="B2C_1A_Translations_De"
   PublicPolicyUri="http://yourtenant.onmicrosoft.com/B2C_1A_Translations_De">

  <BasePolicy>
    <TenantId>yourtenant.onmicrosoft.com</TenantId>
    <PolicyId>B2C_1A_Translations_En</PolicyId>
  </BasePolicy>

  <LocalizedResources Id="api.localaccountsignup.de">
    <LocalizedStrings>
      <LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">E-Mail Adresse</LocalizedString>
      <!-- 其他内容 -->
    </LocalizedStrings>
  </LocalizedResources>

</TrustFrameworkPolicy>

B2C_1A_SignUpSignIn - 继承自 B2C_1A_Translations_De,为依赖方提供了包含所有可用翻译的入口点。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TrustFrameworkPolicy
  xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="https://www.w3.org/2001/XMLSchema"
  xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
  PolicySchemaVersion="0.3.0.0"
  TenantId="your-tenant.onmicrosoft.com"
  PolicyId="B2C_1A_SignUpSignIn"
  PublicPolicyUri="http://your-tenant.onmicrosoft.com/B2C_1A_SignUpSignIn">

  <BasePolicy>
    <TenantId>your-tenant.onmicrosoft.com</TenantId>
    <PolicyId>B2C_1A_Translations_De</PolicyId>
  </BasePolicy>

  <RelyingParty>
    <DefaultUserJourney ReferenceId="SignUpOrSignIn" />
    <TechnicalProfile Id="PolicyProfile">
      <DisplayName>PolicyProfile</DisplayName>
      <Description>The policy profile</Description>
      <Protocol Name="OpenIdConnect" />
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub"/>
        <!-- 声明 -->
      </OutputClaims>
      <SubjectNamingInfo ClaimType="sub" />
    </TechnicalProfile>
  </RelyingParty>
</TrustFrameworkPolicy>

注意 每个自定义策略只能有一个父策略,且您受到继承层次的限制,最多可以有 10 级继承,因此您可能需要在一个文件中包含多种语言。

部署时修改

或者,如果您使用构建管道和 Graph API 将自定义策略部署到您的 B2C 租户,您可以将翻译内容存储在外部(例如 JSON 文件中),并有一个构建任务来读取这些文件,将适当的内容转换为自定义策略 XML,并将其插入到策略文件中,然后再部署到 B2C。

英文:

Policy Hierarchy

Yes, you can set up custom policies so they inherit from another custom policy, creating a chain or hierarchy.

Say you have a custom policy B2C_1A_Base with all your technical profiles and user journeys in, and a custom policy B2C_1A_SignUpSignIn with your relying party definition that executes a sign-up/sign-in journey. You can insert policies between them and you could, for example, have one policy per language, e.g.:

B2C_1A_Base - defines everything used across all child policies.

&lt;TrustFrameworkPolicy
   xmlns:xsi=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;
   xmlns:xsd=&quot;https://www.w3.org/2001/XMLSchema&quot;
   xmlns=&quot;http://schemas.microsoft.com/online/cpim/schemas/2013/06&quot;
   PolicySchemaVersion=&quot;0.3.0.0&quot;
   TenantId=&quot;yourtenant.onmicrosoft.com&quot;
   PolicyId=&quot;B2C_1A_Base&quot;
   PublicPolicyUri=&quot;http://yourtenant.onmicrosoft.com/B2C_1A_Base&quot;&gt;

  &lt;!-- Technical profiles, etc --&gt;

&lt;/TrustFrameworkPolicy&gt;

B2C_1A_Translations_En - inherits everything from B2C_1A_Base, overriding localisation of api.localaccountsignup.en.

&lt;TrustFrameworkPolicy
   xmlns:xsi=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;
   xmlns:xsd=&quot;https://www.w3.org/2001/XMLSchema&quot;
   xmlns=&quot;http://schemas.microsoft.com/online/cpim/schemas/2013/06&quot;
   PolicySchemaVersion=&quot;0.3.0.0&quot;
   TenantId=&quot;yourtenant.onmicrosoft.com&quot;
   PolicyId=&quot;B2C_1A_Translations_En&quot;
   PublicPolicyUri=&quot;http://yourtenant.onmicrosoft.com/B2C_1A_Translations_En&quot;&gt;

  &lt;BasePolicy&gt;
    &lt;TenantId&gt;yourtenant.onmicrosoft.com&lt;/TenantId&gt;
    &lt;PolicyId&gt;B2C_1A_Base&lt;/PolicyId&gt;
  &lt;/BasePolicy&gt;

  &lt;LocalizedResources Id=&quot;api.localaccountsignup.en&quot;&gt;
    &lt;LocalizedStrings&gt;
      &lt;LocalizedString ElementType=&quot;ClaimType&quot; ElementId=&quot;email&quot; StringId=&quot;DisplayName&quot;&gt;Email Address&lt;/LocalizedString&gt;
      &lt;!-- many others --&gt;
    &lt;/LocalizedStrings&gt;
  &lt;/LocalizedResources&gt;

&lt;/TrustFrameworkPolicy&gt;

B2C_1A_Translations_De - inherits everything from B2C_1A_Translations_En, overriding localisation of api.localaccountsignup.de.

&lt;TrustFrameworkPolicy
   xmlns:xsi=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;
   xmlns:xsd=&quot;https://www.w3.org/2001/XMLSchema&quot;
   xmlns=&quot;http://schemas.microsoft.com/online/cpim/schemas/2013/06&quot;
   PolicySchemaVersion=&quot;0.3.0.0&quot;
   TenantId=&quot;yourtenant.onmicrosoft.com&quot;
   PolicyId=&quot;B2C_1A_Translations_De&quot;
   PublicPolicyUri=&quot;http://yourtenant.onmicrosoft.com/B2C_1A_Translations_De&quot;&gt;

  &lt;BasePolicy&gt;
    &lt;TenantId&gt;yourtenant.onmicrosoft.com&lt;/TenantId&gt;
    &lt;PolicyId&gt;B2C_1A_Translations_En&lt;/PolicyId&gt;
  &lt;/BasePolicy&gt;

  &lt;LocalizedResources Id=&quot;api.localaccountsignup.de&quot;&gt;
    &lt;LocalizedStrings&gt;
      &lt;LocalizedString ElementType=&quot;ClaimType&quot; ElementId=&quot;email&quot; StringId=&quot;DisplayName&quot;&gt;E-Mail Adresse&lt;/LocalizedString&gt;
      &lt;!-- many others --&gt;
    &lt;/LocalizedStrings&gt;
  &lt;/LocalizedResources&gt;

&lt;/TrustFrameworkPolicy&gt;

B2C_1A_SignUpSignIn - inherits everything from B2C_1A_Translations_De, providing an entry point for relying parties with all translations available.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
&lt;TrustFrameworkPolicy
  xmlns:xsi=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;
  xmlns:xsd=&quot;https://www.w3.org/2001/XMLSchema&quot;
  xmlns=&quot;http://schemas.microsoft.com/online/cpim/schemas/2013/06&quot;
  PolicySchemaVersion=&quot;0.3.0.0&quot;
  TenantId=&quot;your-tenant.onmicrosoft.com&quot;
  PolicyId=&quot;B2C_1A_SignUpSignIn&quot;
  PublicPolicyUri=&quot;http://your-tenant.onmicrosoft.com/B2C_1A_SignUpSignIn&quot;&gt;

  &lt;BasePolicy&gt;
    &lt;TenantId&gt;your-tenant.onmicrosoft.com&lt;/TenantId&gt;
    &lt;PolicyId&gt;B2C_1A_Translations_De&lt;/PolicyId&gt;
  &lt;/BasePolicy&gt;

  &lt;RelyingParty&gt;
    &lt;DefaultUserJourney ReferenceId=&quot;SignUpOrSignIn&quot; /&gt;
    &lt;TechnicalProfile Id=&quot;PolicyProfile&quot;&gt;
      &lt;DisplayName&gt;PolicyProfile&lt;/DisplayName&gt;
      &lt;Description&gt;The policy profile&lt;/Description&gt;
      &lt;Protocol Name=&quot;OpenIdConnect&quot; /&gt;
      &lt;OutputClaims&gt;
        &lt;OutputClaim ClaimTypeReferenceId=&quot;objectId&quot; PartnerClaimType=&quot;sub&quot;/&gt;
        &lt;!-- claims --&gt;
      &lt;/OutputClaims&gt;
      &lt;SubjectNamingInfo ClaimType=&quot;sub&quot; /&gt;
    &lt;/TechnicalProfile&gt;
  &lt;/RelyingParty&gt;
&lt;/TrustFrameworkPolicy

Note each custom policy can only have one parent and you're limited to 10 levels of inheritance, so you'll probably need to have multiple languages per file.

Deploy-time modification

Alternatively, if you're using build pipelines and Graph API to deploy the custom policies to your B2C tenant you could have the translations stored externally (e.g. in JSON files) and have a build task that reads those files, converts the appropriate content to custom policy XML and inserts them into a policy file before deploying it to B2C.

huangapple
  • 本文由 发表于 2023年7月17日 19:40:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定