Add Content in several languages

Author Message

Carlos Revillo

Friday 16 June 2006 1:55:00 am

Hi. I've developed an extension to insert content in Ez Content Tree. In my site i have two siteaccess, spanish and english.

I want to add content in these two languages from my php script. Right now, i can add spanish content, but i don't know how to add english content...

For adding content, i'm using somethin like

$user_id = 14;
$parentNodeID=365;
$ClassID = 60;
$class =& eZContentClass::fetch( $ClassID );
$contentObject =& $class->instantiate( $userID, 1 );
$contentObject->setAttribute( 'name', "Objeto ");
$contentObjectID = $contentObject->attribute( 'id' );

$nodeAssignment =& eZNodeAssignment::create( array(
				'contentobject_id' => $contentObject->attribute( 'id' ),
				'contentobject_version' => $contentObject->attribute( 'current_version' ),
				'parent_node' => $parentNodeID,
				'sort_field' => 8,
				'sort_order' => 1,
				'is_main' => 1
				)
			);
$nodeAssignment->store();

$version =& $contentObject->version( 1 );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();

$contentObjectAttributes =& $version->contentObjectAttributes();
$contentObjectAttributes[0]->setAttribute( 'data_text', $codigo);
$contentObjectAttributes[0]->store();
$contentObjectAttributes[1]->setAttribute( 'data_text', $http->sessionVariable("p_nombre"));
$contentObject->store();

$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
			'version' => 1 ) );


But, as i said before, i only can add spanish version of that content. How can this script be modified so i can add english content two? thanks.

Kristof Coomans

Friday 16 June 2006 1:58:35 am

Hi Carlos

Which version of eZ publish are you using? 3.8?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Carlos Revillo

Friday 16 June 2006 2:03:48 am

Yes. 3.8.

Kristof Coomans

Saturday 17 June 2006 1:55:29 am

After publishing the Spanish version, you can create a new version with an English translation:

$version = $obj->createNewVersionIn( $selectedEditLanguage );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );

$version->store();

$selectedEditLanguage is in your case "eng-GB".

Now fill the attributes of this new version and publish it.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Carlos Revillo

Saturday 17 June 2006 10:26:00 am

Great!. Thanks so much!.

Martin Jerie

Friday 27 October 2006 2:10:01 am

Please can you show me rest of the code for publish translation

Because when i use code from Carlos example:

$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) );

translation is only draft - how to publish it?

Martin

Martin Jerie

Friday 27 October 2006 5:23:43 am

I found it
I have to change 'version' => 1 to 'version' => 2

Kristof Coomans

Friday 27 October 2006 5:48:01 am

To be correct in any case, use <i>$version->attribute( 'version' )</i>

Cheers

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Tuesday 23 October 2007 7:38:29 pm

Hi.
I use V 3.10 and "createNewVersionIn" works fine for one additional language.
If I use main language and 2 additional languages ($a and $b):

// part A
$version = $obj->createNewVersionIn( $a );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();
...
// part B
$version = $obj->createNewVersionIn( $b );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();

part B always override part A.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.