Forums / Developer / Object translation

Object translation

Author Message

Olivier Versanne

Monday 22 June 2009 1:54:06 am

Hi,

I'm googling on how in PHP with eZ we could to do to create a object with a different language.

I try using some method like setCurrentLanguage on the object, but, when I try to retrieve the dataMap to fill attribute content, the dataMap is empty (without attributes).

So, do you have some sample code, URL, or whatever else?

Olivier Versanne

Monday 13 July 2009 7:42:04 am

Hi!

I'm doing this:

$lang = 'cat-ES';
// $swse is an ezContentObject

if(!in_array($lang, $swse->availableLanguages())){ 
// if the language doesn't exist
          $dataMap = &$swse->dataMap();
          foreach($dataMap as $k => $v){
                    $truc[$k] = $dataMap[$k]->translateTo($lang);
                    $truc[$k]->store();
          }
}
$swse->setCurrentLanguage($lang);
$swse->store();
[...]

And, in admin interface, eZ tell me:

Translations [2]
Existing languages
	Language		Locale	Main	 
	English (WorldWide)	eng-WW

There are 2 existing translation, but it shows me only one.

So that doesn't work... :-(

***

And, another question, I saw in ez's documentation that method "translateTo()" was deprecated. What should we use now?

Thanks for your help!

Carlos Revillo

Monday 13 July 2009 2:10:36 pm

Hi. you can try something like this, supposing english as your main language and catalan as the second one

$object = eZContentObject::fetch( $objectID );

$catalanVersion = $englishObject->createNewVersion( $object->CurrentVersion, true, 'cat-ES', 'eng-GB' );
  
$contentObjectAttributes = $catalanVersion->contentObjectAttributes();

$contentObjectAttributes[0]->setAttribute( 'data_text', $whatever);
$contentObjectAttributes[0]->store();

//fill all your attributes here

eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $catalanVersion->ContentObjectID,
 'version'  =>  $catalanVersion->Version ) );

hope it helps

Olivier Versanne

Wednesday 15 July 2009 2:53:10 am

It's exactly what I was looking for.

That works great, thanks!

eZ debug

Timing: Jan 18 2025 10:19:16
Script start
Timing: Jan 18 2025 10:19:16
Module start 'content'
Timing: Jan 18 2025 10:19:16
Module end 'content'
Timing: Jan 18 2025 10:19:16
Script end

Main resources:

Total runtime0.1578 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 588.7500180.8438
Module start 'content' 0.00690.0088 769.593893.7578
Module end 'content' 0.01570.1420 863.3516521.9844
Script end 0.1577  1,385.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00382.4028200.0002
Check MTime0.00140.8922200.0001
Mysql Total
Database connection0.00120.783910.0012
Mysqli_queries0.107167.88191410.0008
Looping result0.00140.89101390.0000
Template Total0.141489.610.1414
Template load0.00120.761110.0012
Template processing0.140288.865510.1402
Override
Cache load0.00070.463910.0007
Sytem overhead
Fetch class attribute can translate value0.00090.569210.0009
XML
Image XML parsing0.00040.260510.0004
General
dbfile0.00543.4260200.0003
String conversion0.00000.004230.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.0002 secs