Topic: [Modification] Dynamic change default language for forum guests
I have a multilingual website and i use punbb.
My website is in Greek and English language and all i wanted to achieve was to send the user in the specific language of the forum.
So i made some coding to do that!
This modification sets the language by the url.
So, if you will send the user to yourdomain.com/forums/?lang=Greek the default language of the forum will be Greek.
If you will send the user to yourdomain.com/forums/?lang=English the default language of the forum will be English, and so on...
When the user goes into a specific url of the forum with the lang on it, it creates a cookie to remember it so the language will remain as default as the user surfs in the forum.
If the user is registered and login's into the forum, it ignores this new cookie and shows the forum in the language that the user saved when registered!
So all you need to do is:
1. Open the file include/functions.php
2. Find the line 1558
$forum_user['language'] = $forum_config['o_default_lang'];
3. Replace the line 1558 with the following code
if($_GET['lang']) {
if (file_exists('lang/'.$_GET["lang"].'/common.php')) {
setcookie("thedefaultlang", $_GET['lang'], time()+3600);
$TheDefaultLang = $_GET['lang'];
} else {
$TheDefaultLang = $forum_config['o_default_lang'];
}
} else {
if(isset($_COOKIE["thedefaultlang"])) {
$TheDefaultLang = $_COOKIE["thedefaultlang"];
} else {
$TheDefaultLang = $forum_config['o_default_lang'];
}
}
$forum_user['language'] = $TheDefaultLang;
I hope this will help many others who have multilingual websites like me!