Share » Forums » Developer » user editing for different languages

user editing for different languages

user editing for different languages

Monday 06 September 2004 8:31:01 am - 10 replies

Author Message

Joe Wolf

Monday 06 September 2004 8:32:40 am

Hi again,

Alternatively does anyone know where in the kernel contentobjects and written to the database and loaded from the database because then I could modify the code so that users were always saved in the same language (which might solve the problem).

thanks again

Joe

Björn Dieding@xrow.de

Monday 06 September 2004 11:04:16 am

Hi Joe,

this is a known problem that was also mentioned on the conference. eZ has not come up with a solution yet.

Looking for a new job? http://www.xrow.com/xrow-GmbH/Jobs
Looking for hosting? http://hostingezpublish.com
-----------------------------------------------------------------------------
GMT +01:00 Hannover, Germany
Web: http://www.xrow.com/

Joe Wolf

Monday 06 September 2004 11:50:13 am

Hi, and thanks for the reply. Have you any idea when they intend to work on it? Otherwise I may have to code my own login handler, which is a bit daunting!

thanks

Joe

Paul Forsyth

Monday 06 September 2004 2:26:20 pm

This is also discussed here:

http://ez.no/community/forum/developer/user_register_problem_in_multilanguage_website

Same result though: eZ have yet to reply.

What you could do is use your login handler to make sure the first version is in the default language. Then your next version would be the localised version.

Post back here if you have trouble with your handler. But get your hands dirty first ;)

paul

Joe Wolf

Tuesday 07 September 2004 9:04:08 am

Hi Paul,

Have been having a look around and thought that maybe I could put a switch in the register.php class to set the default language after it had gone through instantiating the new object instance i.e.

// Create new user object if user is not logged in
$user =& eZUser::currentUser();
if ( !$user->isLoggedIn() and !$http->hasSessionVariable( "RegisterUserID" ) )
{
    $ini =& eZINI::instance();

    $defaultUserPlacement = $ini->variable( "UserSettings", "DefaultUserPlacement" );

    $userClassID = $ini->variable( "UserSettings", "UserClassID" );
    $class =& eZContentClass::fetch( $userClassID );

    $userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" );	
    $defaultSectionID = $ini->variable( "UserSettings", "DefaultSectionID" );
	
    // Create object by user 14 in section 1
    $contentObject =& $class->instantiate( $userCreatorID, $defaultSectionID );
    $objectID = $contentObject->attribute( 'id' );

SOMEWHERE HERE?

    // Store the ID in session variable
    $http->setSessionVariable( "RegisterUserID", $objectID );

    $userID = $objectID;

    $nodeAssignment =& eZNodeAssignment::create( array('contentobject_id' => $contentObject->attribute( 'id' ), 
                                                       'contentobject_version' => 1, 
                                                       'parent_node' => $defaultUserPlacement, 
                                                       'is_main' => 1 ) ); 
    $nodeAssignment->store();
}
else if ( $http->hasSessionVariable( "RegisterUserID" ) )
{
    $userID = $http->sessionVariable( "RegisterUserID" );
}
else
{
    $userID = $user->attribute( 'contentobject_id' );
}

but after tracking the code all the way through I still can't find where the default language is set. Any hints?

Would I be correct in thinking that I don't need a new login handler because I only need to set the language the first time?

cheers

Joe

Joe Wolf

Tuesday 07 September 2004 9:53:31 am

Okay, so I've figured out that the regional settings in the site.ini file are read in by Ez when creating a new object. This means that I can put a switch somewhere along the way just after the default language is set. I think this still has to be in register.tpl because that is the only place where it's guaranteed that a user is being created for the first time. Let me know if you think I'm on the right track...

cheers

Joe

Paul Forsyth

Wednesday 08 September 2004 2:17:20 am

Joe,

I'll take a look later today if thats okay. In the mean time i found another relevant bug, i believe:

http://ez.no/community/bug_reports/bug_critical_user_information_disapear_when_edited_in_different_language

paul

Joe Wolf

Wednesday 08 September 2004 5:38:34 am

Hi Paul,

I've plugged away and discovered that for both fetching and storing all objects go through the the constructor method of ezcontentobject.php

As a result I tried adding a fix in the constructor:

Original code

    function eZContentObject( $row )
    {
        $this->eZPersistentObject( $row );
	    $this->CurrentLanguage = eZContentObject::defaultLanguage();
    }

Hacked code

    function eZContentObject( $row, $MyLang )
    {
        $this->eZPersistentObject( $row );
		if ($MyLang==''){
        $this->CurrentLanguage = eZContentObject::defaultLanguage();
		}
		else{
		$this->CurrentLanguage = $MyLang;
		}
    }

And in the create method:

Original code

    function &create( $name, $contentclassID, $userID, $sectionID = 1, $version = 1 )
    {
        $row = array(
            "name" => $name,
            "current_version" => $version,
            "contentclass_id" => $contentclassID,
            "permission_id" => 1,
            "parent_id" => 0,
            "main_node_id" => 0,
            "owner_id" => $userID,
            "section_id" => $sectionID,
            'remote_id' => md5( (string)mt_rand() . (string)mktime() ) );
        return new eZContentObject( $row );
	}

Hacked code

    function &create( $name, $contentclassID, $userID, $sectionID = 1, $version = 1 )
    {
        $row = array(
            "name" => $name,
            "current_version" => $version,
            "contentclass_id" => $contentclassID,
            "permission_id" => 1,
            "parent_id" => 0,
            "main_node_id" => 0,
            "owner_id" => $userID,
            "section_id" => $sectionID,
            'remote_id' => md5( (string)mt_rand() . (string)mktime() ) );
		/*addition to make user edit work*/
		if ($contentclassID==4){		
		return new eZContentObject( $row, "eng-GB" );
		}
		/*end of addition*/
		else {	
        return new eZContentObject( $row );
    	}
	}

When I ran this I managed to create a user which was unaccesible in all languages for editing! I'm gonna try also editing the fetch method as well...

Let me know if you have any ideas/suggestions (e.g. This won't work Joe! ;))

cheers

Joe

Paul Forsyth

Wednesday 08 September 2004 7:13:37 am

Hey Joe,

I've started to dig into the code a little and having found that last bug entry im now inclined to think that this is a little more difficult to do. From a custom code point of view anyway. If the bug report is right the user *must* be translated into the new language before editing. This isnt the same as object creation. The code for translation is all embedded into a module view, which is a little hard to use - its not an easy php function :(

However, there may be a very quick workaround. I want to try a proof of concept first if thats ok. In your register.tpl can you test this line?

{let current_user=fetch( user, current_user )}
<form id="Translate" method="post" action="{concat('/content/translate/', $current_user.contentobject_id,'/',sum(1,$current_user.current_version))}"><a href="{"javascript:document.getElementById('Translate').submit();"}">Translate user</a></form>
{/let}

What this should do is, when clicked, take you to the translations page, so the user can be translated into the correct language. Then it should be editable.

You might need to tweak permissions to get this to work from the user side.

If this doesnt work try this code. Im not 100% on correct object version to use....

{let current_user=fetch( user, current_user )}
<form id="Translate" method="post" action="{concat('/content/translate/', $current_user.contentobject_id,'/',$current_user.current_version)}"><a href="{"javascript:document.getElementById('Translate').submit();"}">Translate user</a></form>
{/let}

Hope this makes sense ;)

paul

Joe Wolf

Thursday 09 September 2004 6:31:35 am

Hi Paul,

Thanks for taking the time to look in to it. Unfortunately I couldn't get this to work in either reg.tpl or content/edit.tpl. After changing the user permissions to allow translation I got and object could not be found error.

No matter anyway as the idea of storing a user multiple times for each language is gonna mean a huge db when reasl users are running on the site which I don't really want.

I guess that then leaves me with the option of using another program for shop and user functionality and pluggin it in to EZ. I notice that others have done this too.

With this in mind could you give me a hint as to how I could pull another app into the main ez content area (if it's possible of course!)?

cheers

Joe

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

36 542 Users on board!

Forums menu