FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » ...force the forum to display in another language/theme?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
icon3.gif  Browser language detection hack :D [message #9222 is a reply to message #9128] Mon, 17 March 2003 14:41 Go to previous message
StarLight{PL} is currently offline  StarLight{PL}   Poland
Messages: 22
Registered: March 2003
Karma:
Junior Member
Hello,

First of all, thanks for replying so soon - it was of great help. I've developed a small hack together with a colleague - this hack allows for choosing a language based on user's browser ACCEPT_LANGUAGE settings.

in root_index.php.t, around line 28:
<?php 
    
if ( !$usr->theme )
        if (!isset(
$GLOBALS['forcedTheme'])) $r q("SELECT * FROM {SQL_TABLE_PREFIX}themes WHERE t_default='Y'");
        else {
            
$fthme $GLOBALS['forcedTheme'];
            
$r q("SELECT * FROM {SQL_TABLE_PREFIX}themes WHERE name='$fthme'");
        }
    else
        
$r q("SELECT * FROM {SQL_TABLE_PREFIX}themes WHERE id=".$usr->theme);

?>


in users.inc.t, around line 187 find this code:
<?php 
        $rv
[1] = NULL;
        if( !empty(
$GLOBALS["rid"]) && empty($GLOBALS["HTTP_COOKIE_VARS"]["frm_referer_id"]) ) set_referer_cookie($GLOBALS["r?>
(... cut ...)


and insert this below:

<?php 

/*** SLT & JD: HACK => forcing another theme when unregistered ***/

        
preg_match_all('|(\w\w)(-\w\w)?|'$GLOBALS['HTTP_ACCEPT_LANGUAGE'], $tmp_langs);
        foreach(
$tmp_langs[1] as $tmp_lang)
            if(
in_array($tmp_lang, array('en','pl'))) {
$redir_lang $tmp_lang;
break;
        }
        unset(
$tmp_langs,$tmp_lang);
        if(
$redir_lang=='en'$GLOBALS['forcedTheme']='english_version';

/*** /HACK ***/
    
}
?>


This code sets the 'english_version' theme based on the user's browser ACCEPT LANGUAGE header. The routine sets the first of allowed languages (array('en','pl')) found in the $redir_lang variable. If the first found is en-xx (the regexp cuts the -xx variations, leaving 'en' only) then forcedTheme is set and forum opens in that theme, if not, it falls back to default.

This code is only a hack, perhaps there is more elegant way to do it, but it should be easy to modify it to select "unregistered theme" according to user browser's settings.

Thanks again!
StarLight{PL}
[Message index]
 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message icon3.gif
Previous Topic: How to change the header and footer in FUDForum
Next Topic: rating column
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 09:19:39 GMT 2024

Total time taken to generate the page: 0.04125 seconds