Any way to create objects in a specific lenguage?

Author Message

Pablo C. Vergara Castro

Friday 26 August 2005 1:01:51 am

Hi to all.

I have a Web site with different siteaccess several of this have different RegionalSettings, but want that one of the objects that the user can create will be always in Spanish (that is the language by defect) independently of which the user is in siteaccess in English.

Then my question is, exists some way so that when adding object the system can select in what language will be created?

For example: The user is in the English siteaccess and want to white an information request but independently the siteaccess the system may create this object in Spanish.

I know the way to do this using diferent siteacces one of this with Locale=eng-US but whit ContentObjectLocale=esl-ES but I want to know if are any way to do that with other way.

Lex 007

Friday 26 August 2005 1:16:15 am

Hi,

Yes, this is possible programatically.

To set the language as spanish, first do :

eZContentObject::setDefaultLanguage( $language );

Then create your objetct (code taken from the forum, to create a folder) :

$folderClassID=1;
  
  $class =& eZContentClass::fetch( $folderClassID );
  $folderContentObject =& $class->instantiate( $user->id(), $sectionID );
  
  // Create a node for the object in the tree.
  $nodeAssignment =& eZNodeAssignment::create( array(
                         'contentobject_id' => $folderContentObject->attribute( 'id' ),
                         'contentobject_version' => 1,
                         'parent_node' => $userNodeID,
                         'sort_field' => 2, //Published
                         'sort_order' => 1, //Descending
                         'is_main' => 1));
  $nodeAssignment->store();
    
  // Set a status for the content object version
  $folderContentObjectVersion =& $folderContentObject->version($folderContentObject->attribute( 'current_version' ) );
  $folderContentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
  $folderContentObjectVersion->store();

  // Set the title of the folder.
  $folderContentObjectAttributes =& $folderContentObjectVersion->contentObjectAttributes();
  foreach ($folderContentObjectAttributes as $folderAttribute)
  {
    // Each attribute has an attribute called 'identifier' that identifies it.    

    if ($folderAttribute->attribute("contentclass_attribute_identifier") == "title")
    {
      $folderAttribute->setAttribute("data_text",$folderTitle);
      $folderAttribute->store();
    }
  }
      
  // Now publish the object.
  $operationResult = eZOperationHandler::execute( 'content', 'publish',
                          array( 'object_id' => $folderContentObject->attribute( 'id' ),
                                 'version' => $folderContentObject->attribute('current_version' ) ) );
  
  return;

Finally, reset the language to english :

eZContentObject::setDefaultLanguage( $defaultLanguage );

Hope it helps.

Lex

Pablo C. Vergara Castro

Friday 26 August 2005 1:36:56 am

Well well well...thanks Lex... buut...this way is a low level solution (exactly "php level" solution) and I looking for a "template level" solution, any way like putting a input hidden field to change the object language.

I dont have so much time to create an extension to do the solution you write. I think that this things would be solved in the new ez versions.

Well... if you or somebody know a "template level" solution I will be really thankfull.

Greetings.

David Eriksson

Friday 26 August 2005 2:12:23 am

I believe something like this is under development for a future version.

http://ez.no/community/developer/specs/improved_content_multilangue_support

/David

Xavier Dutoit

Friday 26 August 2005 9:48:15 am

Another problem you're going to have:

If you're on the spanish interface and try to edit an article that isn't translated (ie. you see the english version), then you're going to have an empty screen and lots of error messages (it tries to edit the spanish attributes, but don't find them, as they don't exist).

If anyone has a solution...

X+

http://www.sydesy.com

Bertrand Dunogier

Sunday 28 August 2005 10:53:55 am

That's the main issue of the current multilanguage implementation... I think this is going to be addressed before 4.0 (3.8 or 3.7), don't remember, with the suppression of the so-called default language.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.