Forums / Developer / Creating translated content / Comment42837
Antoine W.
Tuesday 12 April 2005 5:56:15 am
Yes, sure ! Here is my code :
$class =& eZContentClass::fetch( OBJECTCLASSID ); $ContentObject =& $class->instantiate( $user->id(), $sectionID ); //---------------------------------------------------------- // Create a node for the object in the tree. //---------------------------------------------------------- $nodeAssignment =& eZNodeAssignment::create( array( 'contentobject_id' => $ContentObject->attribute( 'id' ), 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'sort_field' => 2, //Published 'sort_order' => 1, //Descending 'is_main' => 1)); $nodeAssignment->store(); //---------------------------------------------------------- // Set a status for the content object version. //---------------------------------------------------------- $ContentObjectVersion =& $ContentObject->version($ContentObject->attribute( 'current_version' ) ); $ContentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT); $ContentObjectVersion->store(); //---------------------------------------------------------- // Set attributes of the Page for the default language //---------------------------------------------------------- $ContentObjectAttributes =& $ContentObjectVersion->contentObjectAttributes(); foreach ($ContentObjectAttributes as $id=>$Attribute) { if($Attribute->attribute("contentclass_attribute_identifier")=="title") { $Attribute->setAttribute("data_text", "my title here"); $Attribute->store(); } if($Attribute->attribute("contentclass_attribute_identifier")=="body") { $Attribute->setAttribute("data_text", "body of my page"); $Attribute->store(); } } //---------------------------------------------------------- // Set attributes of the Page for another language (french) //---------------------------------------------------------- foreach ($ContentObjectAttributes as $id=>$Attribute) { $Attribute =& $attribute->translateTo( "fre-FR" ); $Attribute->sync(); } $contentObject->store(); $translatedAttributes =& $contentObjectVersion->contentObjectAttributes("fre-FR"); foreach ($translatedAttributes as $id=>$Attribute) { if($Attribute->attribute("contentclass_attribute_identifier")=="title") { $Attribute->setAttribute("data_text", "mon titre ici"); $Attribute->store(); } if($Attribute->attribute("contentclass_attribute_identifier")=="body") { $Attribute->setAttribute("data_text", "le contenu de ma page"); $Attribute->store(); } } $ContentObject->store(); //You can do this for each language you want to translate your object. //---------------------------------------------------------- // Now publish the object. //---------------------------------------------------------- include_once ('lib/ezutils/classes/ezoperationhandler.php'); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $ContentObject->attribute( 'id' ), 'version' => $ContentObject->attribute('current_version' ) ) );