英文:
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.
<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">
<!-- Technical profiles, etc -->
</TrustFrameworkPolicy>
B2C_1A_Translations_En - inherits everything from B2C_1A_Base, overriding localisation of 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>
<!-- many others -->
</LocalizedStrings>
</LocalizedResources>
</TrustFrameworkPolicy>
B2C_1A_Translations_De - inherits everything from B2C_1A_Translations_En, overriding localisation of 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>
<!-- many others -->
</LocalizedStrings>
</LocalizedResources>
</TrustFrameworkPolicy>
B2C_1A_SignUpSignIn - inherits everything from B2C_1A_Translations_De, providing an entry point for relying parties with all translations available.
<?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"/>
<!-- claims -->
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
</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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论