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!

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 15:04:23
Script start
Timing: Jan 18 2025 15:04:23
Module start 'layout'
Timing: Jan 18 2025 15:04:23
Module start 'content'
Timing: Jan 18 2025 15:04:24
Module end 'content'
Timing: Jan 18 2025 15:04:24
Script end

Main resources:

Total runtime0.7483 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 587.7969152.6094
Module start 'layout' 0.00450.0022 740.406339.4297
Module start 'content' 0.00670.7404 779.8359480.8750
Module end 'content' 0.74710.0012 1,260.710912.1875
Script end 0.7483  1,272.8984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4136160.0002
Check MTime0.00130.1746160.0001
Mysql Total
Database connection0.00060.080910.0006
Mysqli_queries0.706794.4361600.0118
Looping result0.00040.0578580.0000
Template Total0.724696.820.3623
Template load0.00200.271920.0010
Template processing0.722696.557920.3613
Template load and register function0.00020.022310.0002
states
state_id_array0.00050.071110.0005
state_identifier_array0.00100.133920.0005
Override
Cache load0.00170.2306250.0001
Sytem overhead
Fetch class attribute can translate value0.00070.097120.0004
Fetch class attribute name0.00110.146240.0003
XML
Image XML parsing0.00020.032120.0001
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00060.0747100.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 16
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs