标识要翻译的内容 identifying-content-to-translate
翻译规则为翻译项目中包含或排除的页面、组件和资产标识要翻译的内容。在翻译页面或资产时,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
该文件应用于所有翻译项目。
规则包含以下信息:
- 规则应用于的节点的路径。规则也应用于节点的子级。
- 包含要翻译的内容的节点属性的名称。属性可以特定于某个特定的资源类型或所有资源类型。
例如,您可以创建一个规则,以将作者添加的内容翻译为页面上的所有AEM Foundation文本组件。 此规则可以标识 foundation/components/text 组件的 /content 节点和 text 属性。
已添加一个可用于配置翻译规则的控制台。UI 中的定义将为您填充文件。
有关 AEM 中内容翻译功能的概述,请参阅翻译多语言站点的内容。
页面、组件和资产的规则语法 rule-syntax-for-pages-components-and-assets
规则是一个 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">
<property name="text"/>
</node>
以下示例将翻译所有 text 属性,还会转换基础图像组件的其他属性。 如果其他组件具有同名属性,则该规则不适用于它们。
<node path="/content">
<property name="text"/>
<node resourceType="foundation/components/textimage">
<property name="image/alt"/>
<property name="image/jcr:description"/>
<property name="image/jcr:title"/>
</node>
</node>
用于从页面提取资产的规则语法 rule-syntax-for-extracting-assets-from-pages
使用以下规则语法可包含嵌入在组件中或从组件中引用的资产:
<assetNode resourceType="path to component" assetReferenceAttribute="property that stores asset"/>
每个 assetNode 元素均具有以下特性:
- 一个
resourceType属性,代表解析为组件的路径。 - 一个
assetReferenceAttribute属性,代表存储资产二进制文件(用于嵌入资产)的属性的名称或引用资产的路径.
以下示例从基础图像组件中提取图像:
<assetNode resourceType="foundation/components/image" assetReferenceAttribute="fileReference"/>
覆盖规则 overriding-rules
translation_rules.xml文件由 nodelist 具有多个子元素 node 元素。 AEM 从上到下读取节点列表。如果有多个规则针对同一节点,则使用文件中较低位置的规则。例如,以下规则导致翻译 text 属性中的所有内容,但页面的 /content/mysite/en 分支除外:
<nodelist>
<node path="/content”>
<property name="text" />
</node>
<node path=“/content/mysite/en”>
<property name=“text” translate=“false" />
</node>
<nodelist>
筛选属性 filtering-properties
您可以使用 filter 元素筛选具有特定属性的节点。
例如,以下规则导致翻译 text 属性中的所有内容,但属性 draft 设置为 true 的节点除外。
<nodelist>
<node path="/content”>
<filter>
<node containsProperty="draft" propertyValue="true" />
</filter>
<property name="text" />
</node>
<nodelist>
翻译规则 UI translation-rules-ui
控制台也可用于配置翻译规则。
要访问它,请执行以下操作:
-
依次导航到 工具 和 常规。
-
选择 翻译配置。
从这里,您可以 添加上下文. 这允许您添加路径。
之后,您需要选择上下文,然后单击 编辑。该操作将打开翻译规则编辑器。
您可以通过UI更改以下4个属性: isDeep, inherit, translate 和 updateDestinationLanguage.
isDeep 此属性适用于节点过滤器,默认为true。 它检查节点(或其祖先)是否在过滤器中包含具有指定属性值的属性。如果为 false,则仅检查当前节点。
例如,即使父节点具有属性,子节点也会被添加到翻译作业中 draftOnly 设置为true可标记草稿内容。 此时 isDeep 将发挥作用,并检查父节点是否已将属性 draftOnly 设置为 true 并排除这些子节点。
在编辑器中,您可以选中/取消选中 我s Deep 在 过滤器 选项卡。
以下是生成的xml的示例,当 深 未在UI中选中:
<filter>
<node containsProperty="draftOnly" isDeep="false" propertyValue="true"/>
</filter>
继承 这适用于资产。 默认情况下,每个属性都会继承,但如果您希望某些属性不会在子项上继承,则可以将该属性标记为false,以便该属性仅应用于该特定节点。
在 UI 中,您可以在 属性 选项卡中选中/取消选中 Inherit。
翻译 转换属性仅用于指定是否转换属性。
在 UI 中,您可以在 属性 选项卡中选中/取消选中 Translate。
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"/>
手动编辑规则文件 editing-the-rules-file-manually
随AEM一起安装的translation_rules.xml文件包含一组默认的翻译规则。 您可以编辑该文件以支持翻译项目的要求。例如,您可以添加规则以翻译自定义组件的内容。
如果编辑translation_rules.xml文件,请将备份副本保留在内容包中。 安装AEM Service Pack或重新安装某些AEM包可将当前translation_rules.xml文件替换为原始文件。 要在此情况下恢复您的规则,您可以安装包含备份副本的包。
示例翻译规则文件 example-translation-rules-file
<nodelist>
<!-- translation rules for Geometrixx Demo site (example) -->
<node path="/content/geometrixx">
<!-- 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">
<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">
<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">
<!-- 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>