Topic-icon Yet another issue on multilanguage sites

Active Subscriptions:

None
I have a English + Portuguese site (in the near future, more languages will be available).

I am follwing these instructions: Language Switcher Tutorial for Joomla 1.6

Now, my main problem:
  • how do I redirect a new user to is/hers specific language menu item? (I have a "Welcome EN" menu item and a "Welcome PT" menu item)

Hacking suggestions are welcome.

EDIT: is there a hack I can do to force JFBConnect to treat all users as "new users" (just for testing purposes)?
The topic has been locked.
Support Specialist
14 years 11 months ago #11395 by alzander
Alexandre,
Thanks for the link to the language switcher, I haven't actually looked into that enough yet.. but multi-lingual is something we're always trying to support better.

Before I can answer your question about redirecting, can you let me know how you have the User Creation setting configured in JFBConnect? Mainly curious if we're automatically creating the user or not.. and either way, how the language for that user is set (so we know how to redirect them)..? Once I get a better understanding, I think I should be able to give you some hacks, and we'll also look into the best way to implement this in our stuff for the next release(s).

As for the "treating all users as new users", depending on exactly what you're trying to test, there's a few options. Assuming you just want to do this to test the new user redirection setting, go into the /components/com_jfbconnect/libraries/loginregister.php file. Search for the "function login()" and in here, you'll see a few if's that say "if ($jfbcLibrary->initialRegistration) {..."

You can change these to if (true) and that will make the login sequence think that it's always a first registration. Specifically, there's 2 of these if's. The first (toward the top of the function) is what decides how to do the mapping of the profiles and whether to send the new user email. The lower one (with a lot of code about redirects) is for how to redirect the user. Set either (or both) of these to true depending on how you want to test and you should be good to go.

As always, hope this helps, but if you have other questions, just let us know. I look forward to hearing about your configuration for the menu stuff, and that 2nd section above with the redirects is where the change will be going.. if that helps in case you want to tinker now :)

Alex
The topic has been locked.
Active Subscriptions:

None
Sorry about coming back to this so late... too many things to do, so little time

My "problem" above is not a big deal, since if I redirect all users to a "Welcome" menu item with "language=ALL", it works fine.

Only inconvinence is not being able to translate the title and the alias (and thus the URL) on the resulting page. This would not be a problem if using JoomFish, but JoomFish is only available for Joomla 1.5. :(

I'll solve this with some additional coding.

So, bottom line, for all you JFBConnect users in Joomla 1.6 / 1.7 multilanguage sites: JFBConnect only allows us to redirect to one menu item and that's fine - just use a language="ALL" menu item. Then go hack your templates to change the page title to a JText translated string and (if you know how) do some url rewrites on .htaccess...

If still using 1.5, I think JoomFish will solve this for you (I did not tested it).
The topic has been locked.
Active Subscriptions:

None
Errr... forget about what I said about Joomla 1.6 / 1.7... it seems it is not all this easy. Have to dig on this a little more. Still having language issues on first login.
The topic has been locked.
Active Subscriptions:

None
Here we go again.

I felt the need to edit your code (again - sorry). I hope this will be helpful to solve the redirects in multi-language sites in Joomla 1.6, 1.7

in file /com_jfbconnect/controllers/loginregister.php, function login(), around line 183 I did the following.
        if ($jfbcLibrary->initialRegistration)
        {
            if ($configModel->getSetting('facebook_new_user_redirect_enable'))
            {
                $redirectId = $configModel->getSetting('facebook_new_user_redirect', 'index.php');

                // Lets get the available languages...
                $languages=JLanguageHelper::getLanguages('lang_code');

                // ... and get the current Joomla Language
                $curlanguage = &JFactory::getLanguage(); 
				
                // ... use the current language locale to get the current language "sef" definition
                $locale = $curlanguage->getTag(); 
                $sef=$languages[$locale]->sef;
	
                $db =& JFactory::getDBO();

                // Let's get the link for the menu item configured as a redirect
                $query='SELECT link FROM #__menu WHERE id='.$redirectId;
                $db->setQuery($query);
                $link = $db->loadResult();
		
                // Let's get the menu alias for the current language, based on its link. If not set, get the menu item for "all languanges"
                $query='SELECT alias FROM #__menu 
                              WHERE published>0 AND link='.$db->quote($link).' 
                              AND (language='.$db->quote($locale).' OR language='.$db->quote('*').') 
                              ORDER BY language DESC LIMIT 1';
                $db->setQuery($query);					
                $alias = $db->loadResult();
				
                // If there is a menu item for this specific language, let's use its alias for redirect
                if ($alias && $alias!='') {
                    $redirect='/' .$sef .'/' . $alias;
                } else {
                    $redirect = JRoute::_("index.php?lang=".$sef."&Itemid=" . $redirectId, false);					
                }
				
            } else ... (unchanged code)

This is solving my problem with this particular redirect (the only I am using, for the moment).
I am sure you will come up with a more elegant way of getting the same result.
But please take a look at this, and consider having this kind of solution on all redirects. The idea is getting the administrator to define one redirect by default, but - if it is a multilanguage site - JFBConnect will get that redirect equivalent in other languages.

Seems to me Joomla is going in a way to make JoomFish unnecessary for releases >= 1.6...
The topic has been locked.
Active Subscriptions:

None
Hello? Any feedback on my suggestion and code?
The topic has been locked.
Support Specialist
14 years 9 months ago #12956 by alzander
Alexandre,
Very sorry for the delay on this. I looked over the code when you originally posted it, but obviously forgot to post my thoughts.

From looking it over, everything looks right and, if it works, great! For the 4.0 release coming up, this code won't be in it.. but we are optimizing a bit of how we do the new user and returning user redirects to make sure they're all in the same block of code and are a little more efficient for how the redirect is determined. With this change, it should be easier to break out your language code into a function and then apply it to each type of redirect. I'm sure it won't be that simple, but hopefully, easier :)

I've taken a task note in our bug tracker to look into this for the 4.1 release though. No guarantees that's when it will be implemented, but we'll definitely look into it more over the next month or so after 4.0 is finally out (next week).

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
Here's how I am solving my redirect needs for the time beeing. Maybe is a starting point that change on 4.1.

Every time I do an upgrade, I go edit the "loginregister,php" on controllers folder. And add the following function (it simplifies my work):
function myRedirect($redirectId) {
    // Lets get the available languages... 
    $languages=JLanguageHelper::getLanguages('lang_code'); 

    // ... and get the current Joomla Language 
    $curlanguage = &JFactory::getLanguage(); 
    
    // ... use the current language locale to get the current language "sef" definition 
    $locale = $curlanguage->getTag(); 
    $sef=$languages[$locale]->sef; 

    $db =& JFactory::getDBO(); 

    // Let's get the link for the menu item configured as a redirect 
    $query='SELECT link FROM #__menu WHERE id='.$redirectId; 
    $db->setQuery($query); 
    $link = $db->loadResult(); 

    // Let's get the menu alias for the current language, based on its link. If not set, get the menu item for "all languanges" 
    $query='SELECT alias FROM #__menu 
            WHERE published>0 AND link='.$db->quote($link).' 
            AND (language='.$db->quote($locale).' OR language='.$db->quote('*').') 
            ORDER BY language DESC LIMIT 1'; 
    $db->setQuery($query);                    
    $alias = $db->loadResult(); 
    
            // If there is a menu item for this specific language, let's use its alias for redirect 
    if ($alias && $alias!='') { 
      $redirect='/' .$sef .'/' . $alias; 
    } else { 
      $redirect = JRoute::_("index.php?lang=".$sef."&Itemid=" . $redirectId, false);                    
    } 
    return $redirect;

  }

And then I go making the changes like this on your code
  $itemId = $configModel->getSetting('facebook_new_user_redirect', '0');
  // $menu =& $app->getMenu();
  // $item =& $menu->getItem($itemId);
  // $link = $item->link . "&Itemid=" . $itemId;
  // $redirect = JRoute::_($link, false);
  $redirect = $this->myRedirect($itemId);

Remeber: this works OK if Joomla is setup following docs.joomla.org/Language_Switcher_Tutorial_for_Joomla_1.6 . I do not use JoomFish or other multilanguage tools.

Hope this is usefull.
The topic has been locked.