翻譯規則可識別翻譯專案中包含或排除的頁面、元件和資產的翻譯內容。 當要翻譯頁面或資產時,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.4](/docs/experience-manager-64/sites-deploying/all-repository-restructuring-in-aem-6-4.html?lang=zh-Hant#translation-rules)中的[通用資料庫重組。
規則包含下列資訊:
例如,您可以建立規則,將作者新增的內容轉譯至您頁面上的所有AEM基礎文字元件。 該規則可標識/content
節點和foundation/components/text
元件的text
屬性。
已添加控制台用於配置轉換規則。 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">
<property name="text"/>
</node>
以下示例將轉換所有text
屬性的內容,還將轉換基礎Image元件的其他屬性。 如果其他元件具有相同名稱的屬性,則規則不適用於這些元件。
<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>
使用下列規則語法,以包含內嵌在元件中或從元件參考的資產:
<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會從上到下讀取節點清單。 當多個規則指向相同節點時,會使用檔案中較低的規則。 例如,下列規則會導致翻譯text
屬性中的所有內容,但頁面的/content/mysite/en
分支除外:
<nodelist>
<node path="/content”>
<property name="text" />
</node>
<node path=“/content/mysite/en”>
<property name=“text” translate=“false" />
</node>
<nodelist>
您可以使用filter
元素來篩選具有特定屬性的節點。
例如,下列規則會導致翻譯text
屬性中的所有內容,但屬性draft
設為true
的節點除外。
<nodelist>
<node path="/content”>
<filter>
<node containsProperty="draft" propertyValue="true" />
</filter>
<property name="text" />
</node>
<nodelist>
控制台也可用於配置翻譯規則。
若要存取:
導覽至工具,然後導覽至一般。
選擇翻譯配置。
從這裡,您可以新增內容。 這可讓您新增路徑。
然後,您需要選取您的內容,然後按一下「編輯」。這將開啟翻譯規則編輯器。
您可透過UI變更4個屬性:isDeep
、inherit
、translate
和updateDestinationLanguage
。
isDeep 此屬性適用於節點篩選器,且預設為true。它會檢查節點(或其祖先)是否包含篩選器中具有指定屬性值的屬性。 如果為false,則只會檢查目前節點。
例如,即使父節點的屬性draftOnly
設定為true以標籤草稿內容,子節點仍將被添加到轉譯作業中。 此處isDeep
將開始運行,並檢查父節點是否具有draftOnly
屬性,並排除這些子節點。
在編輯器中,可以在過濾器頁籤中選中/取消選中Is Deep
。
以下是在UI中未勾選「Is Deep」時產生的xml範例:
<filter>
<node containsProperty="draftOnly" isDeep="false" propertyValue="true"/>
</filter>
繼 承這適用於屬性。依預設,會繼承每個屬性,但是如果您希望某些屬性不會繼承到子項上,則可將該屬性標示為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">
<!-- 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>