The DBMS_XMLTRANSLATIONS package provides an interface to perform translations so that strings can be searched or displayed in various languages.
See Also:
For more information, see the Oracle XML DB Developer's GuideThis chapter contains the following sections:
Table 179-1 DBMS_XMLSTORE Package Subprograms
Method | Description |
---|---|
Disables translations in the current session so that query or retrieval will take place on the base document ignoring session language values |
|
Enables translations in the current session |
|
Extracts the translations in |
|
Returns the base document with all the translations |
|
Merges the translations in |
|
Sets the source language to a particular language at the specified XPATH |
|
Returns the document in the specified language |
|
Updates the translation in a particular language at the specified |
This procedure disables translations in the current session so that query or retrieval will take place on the base document ignoring session language values.
This procedure enables translations in the current session. This is the default behavior.
This function and procedure extracts the translations in XLIFF
format from either an XMLTYPE
or a resource in the XDB Repository.
DBMS_XMLTRANSLATIONS.EXTRACTXLIFF( doc IN XMLTYPE, xpath IN VARCHAR2, namespace IN VARCHAR2 := NULL) RETURN XMLTYPE;
DBMS_XMLTRANSLATIONS.EXTRACTXLIFF( abspath IN XMLTYPE, xpath IN VARCHAR2, namespace IN VARCHAR2 := NULL) RETURN XMLTYPE;
Table 179-2 EXTRACTXLIFF Function Parameters
Parameter | Description |
---|---|
|
|
|
|
|
Namespace |
|
Absolute path of the resource from which the |
Extracting the Translation from an XMLTYPE
Let doc =
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - FR </title> <title> Security Class Example - ES </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
Let the xpath = '/securityClass/title'
. The output of EXTRACTXLIFF
will be as follows:
<xliff version='1.1'> <file original='' source-language='en' datatype='xml'> <body> <trans-unit id='/securityClass/title'> <source>Security Class Example</source> <alt-trans> <target xml:lang='fr'>Security Class Example - FR</target> <target xml:lang='es'>Security Class Example - ES</target> </alt-trans> </trans-unit> </body> </file> </xliff>
Extracting the Translation from a Resource
Let the resource '/public/security.xml'
=
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - ES </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> <privlist> <privilege name="privilege1"/> <aggregatePrivilege name="iStorePOApprover"> <title> iStore Purchase Order Approver </title> <privilegeRef name="is:privilege1"/> <privilegeRef name="oa:submitPO"/> <privilegeRef name="oa:privilege3"/> </aggregatePrivilege> <privilege name="privilege2"> <title> secondary privilege </title> <title xdb:srclang="true"> secondary privilege - FR </title> <columnRef schema="APPS" table="PurchaseOrder" column="POId"/> <columnRef schema="APPS" table="PurchaseOrder" column="Amount"/> </privilege> </privlist> </securityClass>
And let XPATH
= '', then the extracted XLIFF
is
<xliff version='1.1'> <file original='/public/security.xml' source-language='en' datatype='xml'> <body> <trans-unit id='/securityClass/title'> <source>Security Class Example</source> <alt-trans> <target xml:lang='fr'>Security Class Example - FR</target> <target xml:lang='es'>Security Class Example - ES</target> </alt-trans> </trans-unit> </body> </file> <file original='/public/security.xml' source-language='fr' datatype='xml'> <body> <trans-unit id='/securityClass/privilege[@name="privilege2"/title'> <source>secondary privilege - FR</source> <alt-trans> <target xml:lang='en'>secondary privilege</target> </alt-trans> </trans-unit> </body> </file> </xliff>
This function returns the base document with all the translations.
For example, for doc =
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
For the above document, this subprogram will return:
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
This function merges the translations in XLIFF
format into either an XMLTYPE
or a resource in the XDB Repository.
DBMS_XMLTRANSLATIONS.MERGEXLIFF( doc IN XMLTYPE, xliff IN XMLTYPE) RETURN XMLTYPE;
DBMS_XMLTRANSLATIONS.MERGEXLIFF( xliff IN XMLTYPE);
Merge Translations into an XMLTYPE
Consider the following input XMLTYPE
:
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - ES </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> <privlist> <privilege name="privilege1"/> <aggregatePrivilege name="iStorePOApprover"> <title> iStore Purchase Order Approver </title> <privilegeRef name="is:privilege1"/> <privilegeRef name="oa:submitPO"/> <privilegeRef name="oa:privilege3"/> </aggregatePrivilege> <privilege name="privilege2"> <title> secondary privilege </title> <title xdb:srclang="true"> secondary privilege - FR </title> <columnRef schema="APPS" table="PurchaseOrder" column="POId"/> <columnRef schema="APPS" table="PurchaseOrder" column="Amount"/> </privilege> </privlist> </securityClass>
Let the input XLIFF
be as follows:
<xliff version='1.1'> <file original='/public/security.xml' source-language='en' datatype='xml'> <body> <trans-unit id='/securityClass/title'> <source>Security Class Example Modified</source> <alt-trans> <target xml:lang='fr'>Security Class Example Mod - FR</target> <target xml:lang='es'>Security Class Example Mod - ES</target> </alt-trans> </trans-unit> <trans-unit id='/securityClass/privilege[@name="privilege2"/title'> <source>secondary privilege modified</source> <alt-trans> <target xml:lang='fr'>secondary privilege mod - FR</target> </alt-trans> </trans-unit> </body> </xliff>
The output of merge will be as follows:
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example Modified </title> <title> Security Class Example Mod - ES </title> <title> Security Class Example Mod - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> <privlist> <privilege name="privilege1"/> <aggregatePrivilege name="iStorePOApprover"> <title> iStore Purchase Order Approver </title> <privilegeRef name="is:privilege1"/> <privilegeRef name="oa:submitPO"/> <privilegeRef name="oa:privilege3"/> </aggregatePrivilege> <privilege name="privilege2"> <title xdb:srclang="true"> secondary privilege modified </title> <title> secondary privilege mod - FR </title> <columnRef schema="APPS" table="PurchaseOrder" column="POId"/> <columnRef schema="APPS" table="PurchaseOrder" column="Amount"/> </privilege> </privlist> </securityClass>
Merge XLIFF Translations into a Resource
If the input document in the above example were to be stored in the repository at '/public/security.xml'
, then merging the above XLIFF
will have the same effect.
This function sets the source language to a particular language at the specified XPATH.
DBMS_XMLTRANSLATIONS.SETSOURCELANG ( doc IN XMLTYPE, xpath IN VARCHAR2, lang IN VARCHAR2, namespace IN VARCHAR2 := NULL) RETURN XMLTYPE;
For example, if doc =
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
the statement
setSourceLang ( doc, '/securityClass/title', 'fr' )
produces
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title> Security Class Example </title> <title xdb:srclang="true"> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
This function returns the document in the specified language.
For example, for doc =
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
TRANSLATEXML
(doc
, 'fr
') will return:
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title> Security Class Example - FR </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>
This function updates the translation in a particular language at the specified XPATH
.
DBMS_XMLTRANSLATIONS.UPDATETRANSLATION( doc IN XMLTYPE, xpath IN VARCHAR2, lang IN VARCHAR2, value IN VARCHAR2, namespace IN VARCHAR2 := NULL) RETURN XMLTYPE;
For example,
updateTranslation ( doc, '/securityClass/title/text()', 'fr', 'Oracle' );
produces
<securityClass xmlns="http://xmlns.oracle.com/xdb/security.xsd" xmlns:is="xmlns.oracle.com/iStore" xmlns:oa="xmlns.oracle.com/OracleApps" targetNamespace="xmlns.oracle.com/example"> <name> securityClassExample </name> <title xdb:srclang="true"> Security Class Example </title> <title> Oracle </title> <inherits-from>is:iStorePurchaseOrder</inherits-from> </securityClass>