Advertisement:

Author Topic: Integration SMF and Mambelfish/Joomfish : How to switch language ?  (Read 38966 times)

Offline sinnys

  • Newbie
  • *
  • Posts: 4
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
« Last Edit: March 19, 2006, 10:33:26 PM by Orstio »

Offline mambo dancer

  • Semi-Newbie
  • *
  • Posts: 11
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #1 on: July 23, 2005, 06:47:24 PM »

Hi,

Have a look at this solution:

http://forum.mamboserver.com/showthread.php?p=256176#post256176 [nofollow]

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #2 on: March 01, 2006, 11:54:25 PM »
Doesn't work, :-(

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

Offline cferd

  • Jr. Member
  • **
  • Posts: 213
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #3 on: March 02, 2006, 11:47:37 AM »
If it helps any, I have 2 languages on my site and accomplished this by modifying only the Mambelfish module.

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

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #4 on: March 03, 2006, 05:50:44 AM »
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

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #5 on: March 03, 2006, 10:24:02 AM »
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:

Code: [Select]
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:

Code: [Select]
// 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:

Code: [Select]
// 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

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #6 on: March 06, 2006, 03:06:43 PM »
Forgot to mention one important thing:

you must out comment this:

Code: [Select]
// 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.

Offline cferd

  • Jr. Member
  • **
  • Posts: 213
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #7 on: March 06, 2006, 04:30:01 PM »
Quote
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?

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.

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #8 on: March 07, 2006, 08:28:58 AM »
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:

Code: [Select]
$hrefVars .= "lang=$iso";
add the following lines:

Code: [Select]
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!
« Last Edit: March 07, 2006, 08:43:09 AM by MadPax »

Offline akede

  • Newbie
  • *
  • Posts: 1
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #9 on: March 08, 2006, 03:23:00 AM »
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

Online Kindred

  • The Mean One
  • Local Moderator
  • SMF Master
  • *
  • Posts: 42,288
  • Gender: Male
    • wagner999 on Facebook
    • Kindred-999 on GitHub
    • www.linkedin.com/in/wdwagner/ on LinkedIn
    • @Kindred_999 on Twitter
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #10 on: March 08, 2006, 08:06:02 AM »
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.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support forums.  Thank you.

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #11 on: March 08, 2006, 08:11:07 AM »
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.

Offline mambo dancer

  • Semi-Newbie
  • *
  • Posts: 11
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #12 on: March 19, 2006, 05:08:18 PM »

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

Offline mambo dancer

  • Semi-Newbie
  • *
  • Posts: 11
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #13 on: March 19, 2006, 05:14:07 PM »


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.


Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #14 on: March 19, 2006, 06:44:39 PM »
Quote
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.

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.

Quote
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.

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

Regards,
Pax

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #15 on: March 19, 2006, 08:45:34 PM »
@ 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?

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish : How to switch language ?
« Reply #16 on: March 19, 2006, 09:31:37 PM »
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:

Code: [Select]
return sefRelToAbs( $href );
IMMEDIATELY
before this return instruction insert the following code:

Code: [Select]
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:
Quote
if( $iso=='en' ) $smflang .= "&language=english";
elseif( $iso=='pt' ) $smflang .= "&language=portuguese";
$href.= $smflang;
   
return sefRelToAbs( $href );

Enjoy!

Offline MadPax

  • Semi-Newbie
  • *
  • Posts: 84
  • Gender: Male
Re: Integration SMF and Mambelfish/Joomfish : How to switch language ?
« Reply #17 on: March 22, 2006, 01:50:25 PM »
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.


Offline mambo dancer

  • Semi-Newbie
  • *
  • Posts: 11
Re: Integration SMF and Mambelfish/Joomfish : How to switch language ?
« Reply #18 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

Offline Aravot

  • Sophist Member
  • *****
  • Posts: 1,057
  • Gender: Male
Re: Integration SMF and Mambelfish/Joomfish : How to switch language ?
« Reply #19 on: March 22, 2006, 03:05:00 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.