Create several language versions of an article

Author Message

Jerome Despatis

Tuesday 06 October 2009 3:14:12 am

Hi,

Thanks to eZPublish, my users can easily create articles in English (for example).

But I'd like that whenever an article is published, the content is automatically translated (and stored) in other languages (for example french, spanish etc...), thanks to Google API translator or any other webservice.

After digging, it seems that the best way to do so is to create a workflow, triggered on pre_publish or post_publish.

I've done so, but now I've great difficulties to create all the versions (french, spanish for example) of my article

Any idea is welcome, I love piece of code...
Or any code in eZ I could look at to get some inspiration, or some extension

I've seen code (powercontent, object creator) to create object, but i don't think it suits my need as I have already an object created. This is other versions of the object, one for each language, i need to create.

Cheers

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();

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 19 2025 01:12:25
Script start
Timing: Jan 19 2025 01:12:25
Module start 'layout'
Timing: Jan 19 2025 01:12:25
Module start 'content'
Timing: Jan 19 2025 01:12:26
Module end 'content'
Timing: Jan 19 2025 01:12:26
Script end

Main resources:

Total runtime0.7421 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 589.2891152.6406
Module start 'layout' 0.00530.0024 741.929739.4766
Module start 'content' 0.00780.7329 781.4063438.5469
Module end 'content' 0.74070.0014 1,219.953112.1250
Script end 0.7421  1,232.0781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4216160.0002
Check MTime0.00120.1637160.0001
Mysql Total
Database connection0.00080.104710.0008
Mysqli_queries0.686692.5189550.0125
Looping result0.00080.1073530.0000
Template Total0.710395.720.3551
Template load0.00210.279020.0010
Template processing0.708295.425620.3541
Template load and register function0.00020.024810.0002
states
state_id_array0.00100.141210.0010
state_identifier_array0.00200.271120.0010
Override
Cache load0.00180.2386220.0001
Sytem overhead
Fetch class attribute can translate value0.00090.118310.0009
Fetch class attribute name0.00150.196830.0005
XML
Image XML parsing0.00010.019710.0001
class_abstraction
Instantiating content class attribute0.00000.001130.0000
General
dbfile0.00150.2019100.0001
String conversion0.00000.001140.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/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: 11
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs