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.