Forums / General / Add Content in several languages

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.

eZ debug

Timing: Jan 18 2025 03:01:32
Script start
Timing: Jan 18 2025 03:01:32
Module start 'content'
Timing: Jan 18 2025 03:01:32
Module end 'content'
Timing: Jan 18 2025 03:01:32
Script end

Main resources:

Total runtime0.1594 sec
Peak memory usage4,096.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 588.8281180.8359
Module start 'content' 0.00670.0067 769.6641101.9766
Module end 'content' 0.01340.1459 871.6406531.7969
Script end 0.1594  1,403.4375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00342.1374200.0002
Check MTime0.00130.8382200.0001
Mysql Total
Database connection0.00090.553810.0009
Mysqli_queries0.115072.12261410.0008
Looping result0.00130.78771390.0000
Template Total0.145591.310.1455
Template load0.00080.501910.0008
Template processing0.144790.788010.1447
Override
Cache load0.00060.363710.0006
Sytem overhead
Fetch class attribute can translate value0.00090.538210.0009
XML
Image XML parsing0.00020.121010.0002
General
dbfile0.00362.2760200.0002
String conversion0.00000.005530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs