Create new translation for an object in pure PHP

Author Message

Guillaume Marty

Wednesday 04 February 2009 8:48:47 am

Hi,

I'm a bit confused about how to create a new translation for an existing object in pure code.

I've not been able to create a new translation in the current version of the object (that is the way how the user interface works). Instead, a new version is created containing the new translation.

Here is my code:

$version = $contentObject->createNewVersionIn( $contentObjectTargetLanguage, $contentObjectSourceLanguage, false, true,  eZContentObjectVersion::STATUS_PUBLISHED );

foreach ( $contentObject->fetchDataMap() as $attribute_identifier => $attribute )
{
	$attribute->fromString( 'New attribute translation' );
	$attribute->store();
}

What am I doing wrong? Maybe it has something to do with createNewVersionIn()...
Please help!

Guillaume Marty

Friday 13 February 2009 8:15:10 am

Any help? Please!

How to create a new language of an object and save attributes the clean way?

nehal shah

Friday 29 April 2011 5:36:39 am

Hi,

I have the same problem.I want to add translation for the current version of the object through php. Here is my code.

$objectID = 6413;
$object = eZContentObject::fetch( $objectID );
$catalanVersion = $englishObject->createNewVersion( $object->CurrentVersion, true, 'hun-HU', 'eng-GB' );

$contentObjectAttributes = $catalanVersion->contentObjectAttributes();
$contentObjectAttributes[0]->setAttribute( 'data_text', 'Urinary System1');
$contentObjectAttributes[0]->store();
$contentObjectAttributes[1]->setAttribute( 'data_text', '202.59.12');
$contentObjectAttributes[1]->store();

but when i run this code it is showing error.

Please anyone has solution for adding translation through php?

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

eZ debug

Timing: Jan 18 2025 00:56:11
Script start
Timing: Jan 18 2025 00:56:11
Module start 'layout'
Timing: Jan 18 2025 00:56:11
Module start 'content'
Timing: Jan 18 2025 00:56:11
Module end 'content'
Timing: Jan 18 2025 00:56:11
Script end

Main resources:

Total runtime0.0185 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 588.0625152.6406
Module start 'layout' 0.00680.0032 740.703139.4766
Module start 'content' 0.01010.0063 780.179789.3828
Module end 'content' 0.01640.0020 869.562534.3047
Script end 0.0184  903.8672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002513.2811140.0002
Check MTime0.00115.8931140.0001
Mysql Total
Database connection0.00094.616010.0009
Mysqli_queries0.003318.020930.0011
Looping result0.00000.069610.0000
Template Total0.00168.610.0016
Template load0.00094.929210.0009
Template processing0.00073.632810.0007
Override
Cache load0.00063.399510.0006
General
dbfile0.001910.417780.0002
String conversion0.00000.043840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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