Prohlížíte obsah nápovědy pro verzi:

Translation rules identify the content to translate for pages, components, and assets that are included in, or excluded from, translation projects. When a page or asset is being translated, AEM extracts this content so that it can be sent to the translation service.

Pages and assets are represented as nodes in the JCR repository. The content that is extracted is one or more property values of the nodes. The translation rules identify the properties that contain the content to extract.

Translation rules are expressed in XML format and stored in the /etc/workflow/models/translation/translation_rules.xml file. The file applies to all translation projects.

Rules include the following information:

  • The path of the node to which the rule applies. The rule also applies to the descendants of the node.
  • The names of the node properties that contain the content to translate. The property can be specific to a specific resource type or to all resource types.

For example, you can create a rule that translates the content that authors add to all AEM foundation Text components on your pages. The rule can identify the /content node and the text property for the foundation/components/text component. 

For an overview of the content translation features in AEM, see Translating Content for Multilingual Sites

Rule Syntax for Pages, Components, and Assets

A rule is a node element with one or more child property elements and zero or more child node elements:

<node path="content path">
          <property name="property name" [translate="false"]/>
          <node resourceType="component path" >
               <property name="property name" [translate="false"]/>
          </node>
</node>

Each of these node elements has the following characteristics:

  • The path attribute contains the path to the root node of the branch to which the rules apply. 
  • Child property elements identify the node properties to translate for all resource types:
    • The name attribute contains the property name.
    • The optional translate attribute equals false if the property is not translated. By default the value is true. This attribute is useful when overriding previous rules. 
  • Child node elements identify the node properties to translate for specific resource types:
    • The resourceType attribute contains the path that resolves to the component that implements the resource type.
    • Child property elements identify the node property to translate. Use this node in the same way as the child property elements for node rules. 

The following example rule causes the content of all text properties to be translated for all pages below the /content node. The rule is effective for any component that stores content in a text property, such as the foundation Text component and the foundation Image component.

<node path="/content">
          <property name="text"/>
</node>

The following example translates the content of all text properties, and also translates other properties of the foundation Image component. If other components have same-named properties, the rule does not apply to them.

<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

Use the following rule syntax to include assets that are embedded in or referenced from components:

<assetNode resourceType="path to component" assetReferenceAttribute="property that stores asset"/>

Each assetNode element has the following characteristics:

  • One resourceType attribute that equals the path that resolves to the component. 
  • One assetReferenceAttribute attribute that equals the name of the property that stores the asset binary (for embedded assets) or the path to the referenced asset.

The following example extracts images from the foundation Image component:

<assetNode resourceType="foundation/components/image" assetReferenceAttribute="fileReference"/>

Overriding Rules

The translation_rules.xml file consists of a nodelist element with several child node elements. AEM reads the node list from top to bottom. When multiple rules target the same node, the rule that is lower in the file is used. For example, the following rules cause all content in text properties to be translated except for the /content/mysite/en branch of pages:

<nodelist>
     <node path="/content”>
           <property name="text" />
     </node>
     <node path=“/content/mysite/en”>
          <property name=“text” translate=“false" />
     </node> 
<nodelist>

Filtering Properties

You can filter nodes that have a specific property by using a filter element.

For example, the following rules cause all content in text properties to be translated except for the nodes that have the property draft set to true.

<nodelist>
    <node path="/content”>
    	<filter>
			<node containsProperty="draft" propertyValue="true" />
	    </filter>
        <property name="text" />
    </node>
<nodelist>

Editing the Rules File

The translation_rules.xml file that is installed with AEM contains a default set of translation rules. You can edit the file to support the requirements of your translation projects. For example, you can add rules so that the content of your custom components are translated. 

If you edit the translation_rules.xml file, keep a backup copy in a content package. Installing AEM service packs or reinstalling certain AEM packages can replace the current translation_rules.xml file with the original. To restore your rules in this situation, you can install the package that contains your backup copy.

Poznámka:

After you create the content package, rebuild the package each time you edit the file.

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>

Tato práce podléhá licenci Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.  Na příspěvky ze služeb Twitter™ a Facebook se nevztahují podmínky licence Creative Commons.

Právní upozornění   |   Zásady ochrany osobních údajů online