Integration SMF and Mambelfish/Joomfish : How to switch language ?

Started by sinnys, March 01, 2005, 05:43:27 AM

Previous topic - Next topic

sinnys

Hi everybody,

I've not found any topics about my problem.

My website use Mambo 4.5.1, SMF 1.0.1 and the last SMF Bridge version (3.02).
I use Mambelfish to switch between different languages.

How to force SMF and the bridge to be in the correct language, depending on what choose the user ? Should I add a specific value to a link to do that or is there an other way ?

thanks for your answers,
Sinnys


MadPax

Doesn't work, :-(

And I did do the substitution and all as posted. It beats me why it doesn't work though.

cferd

If it helps any, I have 2 languages on my site and accomplished this by modifying only the Mambelfish module.

I replaced:
<?php echo mosLoadComponent'mambelfish' ); ?>
with:
<?php
        
global $_MAMBELFISH_MANAGER;
        require_once( 
"$mosConfig_absolute_path/components/com_mambelfish/mambelfish.html.php" );
        
$lang MambelFish::discoverLanguage($database);
         if( 
$lang!='en' ) {
         
$smflang .= '&language=english';
         
$lang_name .= 'English';
         }
         elseif( 
$lang!='es' ) {
         
$smflang .= '&language=spanish';
         
$lang_name .= 'Español';
         }
        
$langActive MambelFishManager::getActiveLanguages();
        for (
$i=0$i count($langActive ); $i++) {
                if(
$langActive[$i]->iso != $lang) {
?>
<a href="<?php echo $mosConfig_live_site .'/' HTML_mambelfish::_createHRef ($langActive[$i]->iso). $smflang;?>"><?php echo $lang_name?></a>
<?php                }
        }
?>

No need to hack any core files this way.
I'm sure it can be changed to include more than 2 languages with the 'elseif', though I really haven't had the need to try.

MadPax

Cferd you're a Genious!

It has got the main concept of adding to the end of the link string the "&language=whateveryourlanguageisinfact".

Works like a charm.

Only things I found were:

1. The flags dissapeared in my module. I have to look through the code, why this happened.
2. It didn't work with SEF on in Joomla site configuration SEO TAB. What would I need to substitute to make this compatible. An if statement to check i sef is active?

Regards,
And thnx mate, you saved my day. Wth these two small points out of the way the solution is 100% neat.

Pax

MadPax

OK! News about this whole thing.

Two methods two different instances of facts and workarounds. Thank you all for your input, both here and at the mamboserver forums' thread.

The two methods are:


  • Hacking the SMF 1.1 RC2 source/load.php file.
  • Hakcing the Mambelfish mod_mambelfish.php file.

Numero 1

the source/load file mod that mambo dancer pointed me too at the mamboserver forums seemed to be ok and demos presented there were working. I couldn't for the life of me put it to work what they said the solution to be was:

function loadLanguage($template_name, $lang = '', $fatal = true)
{
global $boarddir, $boardurl, $user_info, $language_dir, $language, $settings, $txt,$lang ;
static $already_loaded = array();
// Default to the user's language.
if ($lang=='En') { $lang='english'; $language=$lang;}
else if ($lang=='De') { $lang='german'; $language=$lang;}
else if ($lang=='Fr') { $lang='french'; $language=$lang;}
else if ($lang=='Nl') { $lang='dutch'; $language=$lang;}

$user_info['language'] = $lang;


// Fallback on the default theme if necessary.
$attempts = array(
array($settings['theme_dir'], $template_name, $lang, $settings['theme_url']),
array($settings['theme_dir'], $template_name, $language, $settings['theme_url']),
array($settings['default_theme_dir'], $template_name, $lang, $settings['default_theme_url']),
array($settings['default_theme_dir'], $template_name, $language, $settings['default_theme_url'])
);


and that you should make sure that $db_show_debug was set as global in the function.

SOLUTION
Well if you apply this as is it won't work for a 1.0.7/8 Joomla + SMF 1.1 RC2 installation. The reason is that the functions declarations are a bit different now from what they were when Mambo Dancer started his thread at MS.

First thing you will notice is that in SMF 1.1 RC2 $db_show_debug is already declared so the hack should work straight away. It doesn't because $lang is now (in this new version) local to the function. So you need to make amends and declare it global to.

Second is that in the new version the second part of the code:

// Fallback on the default theme if necessary.
$attempts = array(
array($settings['theme_dir'], $template_name, $lang, $settings['theme_url']),
array($settings['theme_dir'], $template_name, $language, $settings['theme_url']),
array($settings['default_theme_dir'], $template_name, $lang, $settings['default_theme_url']),
array($settings['default_theme_dir'], $template_name, $language, $settings['default_theme_url'])
);


is not necessary any more because SMF 1.1 RC2 already resolves these by using the following code:

// Obviously, the current theme is most important to check.
$attempts = array(
array($settings['theme_dir'], $template_name, $lang, $settings['theme_url']),
array($settings['theme_dir'], $template_name, $language, $settings['theme_url']),
);

// Do we have a base theme to worry about?
if (isset($settings['base_theme_dir']))
{
$attempts[] = array($settings['base_theme_dir'], $template_name, $lang, $settings['base_theme_url']);
$attempts[] = array($settings['base_theme_dir'], $template_name, $language, $settings['base_theme_url']);
}

// Fallback on the default theme if necessary.
$attempts[] = array($settings['default_theme_dir'], $template_name, $lang, $settings['default_theme_url']);
$attempts[] = array($settings['default_theme_dir'], $template_name, $language, $settings['default_theme_url']);


If you follow these steps and only add the global $lang and the first part of Mambo Dancer's code you're all set.

Oh and you can retain the nifty little flags.

Numero 2
This is the mambelfish hack and it bases itself around the interesting fact that if you had your smf forum unwrapped and had more that one language installed you could simply append &language=yourlanguagenamehere to te url in the address bar of your browser and voilá the forum changes language without your having to go into your profile or the forum's default language and change it.

SOLUTION
That's exactly what cferd's code does for you upon clicking the language of your choice in the mambelfish module. He's got an additional nice functionality in that mambelfish won't show the current language as a choice.

On the other hand you loose 2 things as mentioned before:

  • The flags dissapear in mambelfish module and is substituted by the test you define in the $lang_name variable.
  • It doesn't work with SEF turned on in the Joomla site configuration SEO TAB.

If you can live with this that's ok! The code works fine.
What you must have in mind though is that the whole mosLoadComponent( 'mambelfish' ) call is bypassed. I still don't see the implications this might have in the long run. If any of you kind readers got an idea, feel free to comment.

CONCLUSION
I must confess that I have lost all my hope with mambo dancer's solution but when I stumbled accross the new version code's differences with the older code the solution is simple and neat.

I prefer the smf hack because the whole problem is that of smf changing its UI. I would rather have mambelfish do its thing and not change anything in it.

Cferd's solution is for those who prefer to have smf upgradeable in the future without remembering about the hack.

Well that's it enjoy and again thanks for all the help guys.

Regards,
Pax

MadPax

Forgot to mention one important thing:

you must out comment this:

// Default to the user's language.
//if ($lang == '')
// $lang = $user_info['language'];


Otherwise the forum will allways jump back to the language defined via administration.

cferd

QuoteOnly things I found were:

1. The flags dissapeared in my module. I have to look through the code, why this happened.
2. It didn't work with SEF on in Joomla site configuration SEO TAB. What would I need to substitute to make this compatible. An if statement to check i sef is active?

1. Flags appearing is just a matter of changing 'English'; with '<img src="...image-url" />'; for each language.
2. I have other issues with SEF other than languages, so I don't use it. Sorry I can't help you there, but I don't see how it would be hard to change the call to make it work with SEF on.

MadPax

OK fellas,

There is news regarding the solutions I have mentioned above.

They DO NOT WORK flawlessly.

After some investigation I came to the conclusion that trying to hack smf via the load script is not viable because of the possible combinations in server settings default language and the user defined language and wether the users can change their languages or not.

The nicest solution I came up with (well you guys will tell me if it's the nicest or not) was to get back to mambelfish and try to make it smf compatible.

To do this open mablefish.html.php (NOT the module!!!). You can find this file in ../components/com_mambelfish.

find the function declared as _createHRef( $iso )

right after:

$hrefVars .= "lang=$iso";

add the following lines:

if( $iso=='en' ) $smflang .= "&language=english";
elseif( $iso=='pt' ) $smflang .= "&language=portuguese";
$hrefVars.= $smflang;


Do as many esleifs you want for the languages you got installed.

If you want I can go into the code and enhance it to look up the Joomla installed languages and map the joomla language names (which are in their original form) to the smf ones (these are in english), so that there's no need to hard code the language names.

Also it might be interesting to have the bridge installer see if smf is installed and enable these lines of code. In the future the bridge could include this hack as included.

Enjoy.


Thanks cferd and mambodancer for all the clues. You guys rock!

akede

I'm wondering why you are using the $lang variable, as this is only available when the user switches (right in this moment).

Normally you are supposed to use the $mosConfig_lang variable which always holds the Joomla!/Mambo language name.

The fish is also creating a global variable called $iso_client_lang. This is holding the iso code configured in the Fish configuration.

Alex

Kindred

akede,

they don't want to change the board for EVERYONE... just for the users that selected a langauge change.... so $mosConfig_lang is not appropriate.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MadPax

Hello Alex,

You are perfectly correct when suspecting about the usage of $lang. That's why I mentioned that I started having problems with mambodancer's solution and variants.

In short forget $lang.
If I were you I would forget $mosConfig_lang too because we want the sites to change languages dynamically.

Now your suggestion of the use of $iso_client_lang is right on the spot though. If you look at the place I suggested using the small hack in mambelfish.html.php the code is inserted into a loop that traverses the $iso_client_lang variable (which if I am not wrong is an array of all installed languages - don't know its dimension though maybe it has other things besides the languages, I didn't check that deep!).

So to put it more simply: _createHRef method is called from above upon request of the mambelfish loader which checks all joomla languages and creates the necessary hrefs for display. So if I then tell the href creator method to append &language='whateveryourlanguagehere' to the final url smf will switch languages no matter what the default forum language is defined by admin.

Of course this will be overridden if you give your registered users the capability to choose forum language. If you choose not to give them this right then mambelfish will allways choose the forum language for you. Also and this is the big thing, all links (hrefs) rendered on the wraped forum will correctly jump to the apropriate language version.

With the previous solutions if you were reading the forum in english with, say the default forum language of german and you jumped to the online or members link via the menu the foerum would get rendered in german.

With my suggestion you can have both solutions working fine, no matter what rights you give your users. Actually this whole thing is only an issue upon the first visits of guests to your site. As soon as a user registered his language of preference is "memorized".

The only problem is if you give users the option of choosing their forum default language and you do not update the site to their specific language, say greek for instance. They will end up not liking your not having translated your site content to greek, lol. Well if nothing else, this will make mambelfish sites stay updated.

I don't know if I am making too much sense here as I was writing this with a direct streaming connection to my brain. If you have any more doubts or see that I might be wrong somwhere down the road of my reasoning, heck feel free correct me.

Thnx for even taking the time considering what mambodancer, cferd and I have done.

Regards,
Pax

P.S.sry for the long post.
P.S.2 just tried to post this and Kindred was a bit faster than I regarding the global J! language. Thnx Kindred. Next time I'll choke my verborrhea.

mambo dancer


Madpax,

Meanwhile I've upgraded to mambo 453, Community builder RC2 and Simplemachines 1.1RC2.

So going through lots of multilanguage fixing fun again ;)

My solution didn't seem to work anymore - only on the main forum page, but I've implemented your fix, and it works like a charm. Thanks for the work on that.

Regards,

Mambo dancer

mambo dancer



MadPax,

I had also rewritten some code behind the edit profile. In this new version edit profile automatically links back to the mambo profile, but before it did not. So I need to review that code.

There was a piece of code where I linked a new mambo picture to a picture in the simplemachines code. If you 're interested in that code I ll post it here.

Regards.


MadPax

QuoteMy solution didn't seem to work anymore - only on the main forum page, but I've implemented your fix, and it works like a charm. Thanks for the work on that.

You're most welcome Mambodancer!

Without your introwork, so to speak, I wouldn't have had the balls to get into the meddley.

Quote
I had also rewritten some code behind the edit profile. In this new version edit profile automatically links back to the mambo profile, but before it did not. So I need to review that code.

Do you think that it is a good idea to inhibit users getting to their smf profile? There are so many settings there that control very personal tastes in browsing forums. My best bet would be to extend the smf profile with custom fields so that it's all there in one neat place.

QuoteThere was a piece of code where I linked a new mambo picture to a picture in the simplemachines code. If you 're interested in that code I ll post it here.

What do you mean link to the smf picture? Can you elaborate a bit on this?

Regards,
Pax

MadPax

@ akede,

Hello Alex,

I don't really know if you're going to read this (I'll probably try to make you though ;)) but here goes the question anyway.

I've been trying to apply this little hack on Joomfish v1.7 Beta and I am having some difficulty. It seems that createhref function is no longer acting as before. Or at least it's in different contexts because the function itself suffered no alteration.

Can you confirm this?

MadPax

OK!

HERE WE GO. Joomfish 1.7 can be made SMF 1.1 RC2 aware as well.

Here's what you got to do.

find the file: /yoursite/modules/mod_jflanguageselection.php

in function _createHRef( $iso ), just before the end of it you find:

return sefRelToAbs( $href );

IMMEDIATELY
before this return instruction insert the following code:

if( $iso=='en' ) $smflang .= "&language=english";
        elseif( $iso=='pt' ) $smflang .= "&language=portuguese";
        $href.= $smflang;

and do as many elseifs as you need.

New final code would look like this:
Quoteif( $iso=='en' ) $smflang .= "&language=english";
elseif( $iso=='pt' ) $smflang .= "&language=portuguese";
$href.= $smflang;
   
return sefRelToAbs( $href );

Enjoy!

MadPax

You guys should be aware of one thing!

When users register themselves it doesnt' matter what language they are viewing their site with. When they register, their default language will be the forum's default language. So they might get a situation where the site is in one language (the one they've been watching the site with) and the forums in another. I will check further into this.


mambo dancer


Ah there is a fish 1.7 now? Still at 1.5 here! Where can I find that one?

Regards

Aravot

Quote from: mambo dancer on March 22, 2006, 02:49:09 PM

Ah there is a fish 1.7 now? Still at 1.5 here! Where can I find that one?

Regards

Joom!Fish 1.7, by the way it is for Joomla.

Advertisement: