翻译规则可标识要翻译的内容,这些内容适用于翻译项目中包含或排除的页面、组件和资产。 当页面或资产被翻译时,AEM会提取此内容,以便将其发送到翻译服务。
页面和资产在JCR存储库中表示为节点。 提取的内容是节点的一个或多个属性值。 翻译规则标识包含要提取内容的属性。
翻译规则以XML格式表示,并存储在以下可能位置:
/libs/settings/translation/rules/translation_rules.xml
/apps/settings/translation/rules/translation_rules.xml
/conf/global/settings/translation/rules/translation_rules.xml
该文件适用于所有翻译项目。
升级到6.4后,建议将文件从/etc移动。 有关更多详细信息,请参阅AEM 6.5](/docs/experience-manager-65/sites-deploying/all-repository-restructuring-in-aem-6-5.html?lang=zh-Hans#translation-rules)中的[常见存储库重组。
规则包括以下信息:
例如,您可以创建一个规则,用于转换作者添加到页面上所有AEM foundation Text组件的内容。 规则可以标识/content
节点和foundation/components/text
组件的text
属性。
添加了一个console,用于配置转换规则。 UI中的定义将为您填充文件。
有关AEM中内容翻译功能的概述,请参阅多语言站点内容翻译。
AEM支持在资源类型和引用属性之间进行一对一映射,以转换页面上的引用内容。
规则是一个node
元素,其中包含一个或多个子元素property
和零个或多个子元素node
:
<node path="content path">
<property name="property name" [translate="false"]/>
<node resourceType="component path" >
<property name="property name" [translate="false"]/>
</node>
</node>
每个node
元素具有以下特征:
path
属性包含规则所应用分支的根节点的路径。
子property
元素标识要转换的所有资源类型的节点属性:
name
属性包含属性名称。translate
属性等于false
。 默认情况下,值为true
。 此属性在覆盖以前的规则时很有用。子node
元素标识要针对特定资源类型进行转换的节点属性:
resourceType
属性包含解析到实现资源类型的组件的路径。property
元素标识要转换的节点属性。 以与节点规则的子property
元素相同的方式使用此节点。下面的示例规则导致转换/content
节点下所有页面的所有text
属性的内容。 规则对于在text
属性中存储内容的任何组件(如基础文本组件和基础图像组件)都有效。
<node path="/content?lang=zh-Hans">
<property name="text"/>
</node>
下面的示例转换所有text
属性的内容,还转换基础Image组件的其他属性。 如果其他组件具有同名属性,则规则不适用于这些组件。
<node path="/content?lang=zh-Hans">
<property name="text"/>
<node resourceType="foundation/components/textimage">
<property name="image/alt"/>
<property name="image/jcr:description"/>
<property name="image/jcr:title"/>
</node>
</node>
使用以下规则语法来包括嵌入到组件中或从组件中引用的资产:
<assetNode resourceType="path to component" assetReferenceAttribute="property that stores asset"/>
每个assetNode
元素具有以下特征:
resourceType
属性,它等于解析到组件的路径。assetReferenceAttribute
属性,它等于存储资产二进制(对于嵌入式资产)或引用资产路径的属性的名称。下面的示例从基础图像组件中提取图像:
<assetNode resourceType="foundation/components/image" assetReferenceAttribute="fileReference"/>
translation_rules.xml文件由nodelist
元素组成,其子元素为node
。 AEM从上到下读取节点列表。 当多个规则目标同一节点时,将使用文件中较低的规则。 例如,以下规则导致除页面的/content/mysite/en
分支外,text
属性中的所有内容都要进行翻译:
<nodelist>
<node path="/content%E2%80%9D%3E%20%20%20%20%20%20%20%20%20%20%20%3Cproperty%20name?lang=zh-Hans="text" />
</node>
<node path=“/content/mysite/en”>
<property name=“text” translate=“false" />
</node>
<nodelist>
可以使用filter
元素筛选具有特定属性的节点。
例如,以下规则导致除属性draft
设置为true
的节点外,text
属性中的所有内容都要进行转换。
<nodelist>
<node path="/content%E2%80%9D%3E%20%20%20%20%20%3Cfilter%3E%20%20%20%3Cnode%20containsProperty?lang=zh-Hans="draft" propertyValue="true" />
</filter>
<property name="text" />
</node>
<nodelist>
控制台也可用于配置翻译规则。
要访问它:
导航到工具,然后导航到常规。
选择转换配置。
从此处,您可以添加上下文。 这允许您添加路径。
然后,您需要选择上下文,然后单击编辑。 这将打开翻译规则编辑器。
您可以通过UI更改4个属性:isDeep
、inherit
、translate
和updateDestinationLanguage
。
isDeep 此属性适用于节点过滤器,默认情况下为true。它检查节点(或其祖先)是否在筛选器中包含具有指定属性值的属性。 如果为false,则仅检查当前节点。
例如,即使父节点将属性draftOnly
设置为true以标记草稿内容,子节点也会被添加到转换作业中。 此处isDeep
开始运行并检查父节点是否将属性draftOnly
作为true并排除这些子节点。
在编辑器中,您可以选中/取消选中过滤器选项卡中的深。
以下是在UI中未选中Is Deep时生成的xml的示例:
<filter>
<node containsProperty="draftOnly" isDeep="false" propertyValue="true"/>
</filter>
inherit这适用于属性。默认情况下,每个属性都是继承的,但如果您希望某些属性不在子项上继承,则可以将该属性标记为false,以便仅在该特定节点上应用该属性。
在UI中,您可以选中/取消选中属性选项卡中的继承。
转 换属性仅用于指定是否转换属性。
在UI中,您可以选中/取消选中属性选项卡中的翻译。
updateDestinationLanguage 此属性用于没有文本但语言代码的属性,例如jcr:language。用户不是在翻译文本,而是在从源到目标的语言区域设置中。 此类属性不会发送用于翻译。
在UI中,您可以在属性选项卡中选中/取消选中转换,但对于具有语言代码作为值的特定属性。
为了帮助阐明updateDestinationLanguage
和translate
之间的差异,以下是仅包含两个规则的上下文的一个简单示例:
xml中的结果将如下所示:
<property inherit="true" name="text" translate="true" updateDestinationLanguage="false"/>
<property inherit="true" name="jcr:language" translate="false" updateDestinationLanguage="true"/>
随AEM安装的translation_rules.xml文件包含一组默认的翻译规则。 您可以编辑文件以支持翻译项目的要求。 例如,您可以添加规则,以便对自定义组件的内容进行翻译。
如果编辑translation_rules.xml文件,请在内容包中保留一个备份副本。 安装AEM Service Pack或重新安装某些AEM包可以将当前的translation_rules.xml文件替换为原始文件。 要在此情况下恢复规则,可以安装包含备份副本的包。
创建内容包后,每次编辑文件时都重新构建该包。
<nodelist>
<!-- translation rules for Geometrixx Demo site (example) -->
<node path="/content/geometrixx?lang=zh-Hans">
<!-- list all node properties that should be translated -->
<property name="jcr:title" /> <!-- translation workflows running on content saved in /content/geometrixx, will extract jcr:title values independent of the component. -->
<property name="jcr:description" />
<node resourceType ="foundation/components/image"> <!-- translation workflows running on content saved in /content/geometrixx, will extract alternateText values only for Image component. -->
<property name="alternateText"/>
</node>
<node resourceType ="geometrixx/components/title">
<property name="richText"/>
<property name="jcr:title" translate="false"/> <!-- translation workflows running on content saved in /content/geometrixx, will not extract jcr:title for Title component, but instead use richText. -->
</node>
<node pathContains="/cq:annotations?lang=zh-Hans">
<property name="text" translate="false"/> <!-- translation workflows running on content saved in /content/geometrixx, will not extract text if part of cq:annotations node. -->
</node>
</node>
<!-- translation rules for Geometrixx Outdoors site (example) -->
<node path="/content/geometrixx-outdoors?lang=zh-Hans">
<node resourceType ="foundation/components/image">
<property name="alternateText"/>
<property name="jcr:title" />
</node>
<node resourceType ="geometrixx-outdoors/components/title">
<property name="richText"/>
</node>
</node>
<!-- translation rules for ASSETS (example) -->
<node path="/content/dam?lang=zh-Hans">
<!-- configure list of metadata properties here -->
<property name="dc:title" />
<property name="dc:description" />
</node>
<!-- translation rules for extracting ASSETS from SITES content, configure all components that embed or reference assets -->
<assetNode resourceType="foundation/components/image" assetReferenceAttribute="fileReference"/>
<assetNode resourceType="foundation/components/video" assetReferenceAttribute="asset"/>
<assetNode resourceType="foundation/components/download" assetReferenceAttribute="fileReference"/>
<assetNode resourceType="foundation/components/mobileimage" assetReferenceAttribute="fileReference"/>
<assetNode resourceType="wcm/foundation/components/image" assetReferenceAttribute="fileReference"/>
</nodelist>