Share » Forums » Developer » Object translation

Object translation

Object translation

Monday 22 June 2009 1:54:06 am - 3 replies

Modified on Monday 13 July 2009 7:42:27 am by Olivier Versanne

Author Message

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!

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu