Share » Forums » Developer » Create several language versions of...

Create several language versions of an article

Create several language versions of an article

Tuesday 06 October 2009 3:14:12 am - 2 replies

Author Message

Jerome Despatis

Tuesday 06 October 2009 3:38:28 am

Hum after reading my post, and reading the 'concepts and basics' of eZPublish, I've done a big mistake:

A version of an object already contains all the languages, so I "just" need to add in the published version all the languages (spanish and french in my example)

Any help is welcome

Jerome Despatis

Tuesday 06 October 2009 6:35:08 am

Hi again,

I've found the working following code.

Someone could confirm me this code is ok ? or maybe is there a better way to do so ?

This code translates an english article into russian for example

        $db = eZDB::instance();
        $db->begin();

        $newVersion = $object->createNewVersion( $object->CurrentVersion, true, 'rus-RU', 'eng-GB' );
        $contentObjectAttributes = $newVersion->contentObjectAttributes();

        foreach($contentObjectAttributes as $key => $objectAttribute) {
          if ($objectAttribute->contentClassAttributeCanTranslate()) {
            $from = $objectAttribute->attribute('data_text');

            // Translation process taking $from as an argument and returning $output,
            // which is the russian translation of $from for example

            $objectAttribute->setAttribute('data_text', $output);
            $objectAttribute->store();
          }
        }
        $result = eZOperationHandler::execute( 'content', 'publish',
                                               array( 'object_id' => $object->attribute( 'id' ),
                                                      'version' => $newVersion->attribute( 'version' ) ) );

        $db->commit();

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

36 542 Users on board!

Forums menu