Yes, I have made such a mod:
MultiLanguage Mod
=================
for PunBB v.1.1.x
some considerations:
- language selection will be placed as a primary function in
the main navigational links, since we want language selection
to be available to all users, including guests.
- language selection will not be placed on user's profile page,
since we do not want this functionality to suddenly move there
when the user decides to register.
- language selection will not be displayed on forum installations
with only one installed language.
with these objectives in mind, off we go.
first, add a "language" column to the "user" table - on mysql,
this is done with the following statement:
ALTER TABLE `users` ADD `language` VARCHAR( 10 ) DEFAULT NULL;
in "config.php", after setting $language (which now determines
the default language), add an array of installed languages:
$languages = array(
'en' => 'English',
'de' => 'German',
'ru' => 'Russian'
);
defining $languages in "config.php" is of course optional, and
language selection will not be present on the users' profiles
page if only one language is installed.
some sections in "common.php" need to be moved around a bit.
cut the code between the following remark and the next:
// Check/update/set cookie and fetch user info
paste it before the section that begins with the remark:
// Enable output buffering
then cut the code section following this remark:
// Attempt to load the common language file
and paste that before the section with this remark:
// Enable output buffering
these changes won't immidiately affect anything, they're just
necessary because we need to change the language setting in
check_cookie() before the language files are loaded.
so next up is "functions.php", where we have to load the
users language setting into the global $language .. go to
the function with the header:
function check_cookie(...)
add $language to the global statement, like so:
global $language, $db, $pun_config, $pun_root, $cookie_name....
^ there
then find the following line:
$expire = $now + 31536000; // The cookie expires after a year
and paste the following chunk of code after it:
// Switch to language specified by cookie:
if (strlen($_COOKIE[$cookie_name.'_lang']) > 0) {
if (file_exists($pun_root.'lang/'.$_COOKIE[$cookie_name.'_lang']))
$language = $_COOKIE[$cookie_name.'_lang'];
}
now we must initialize the language cookie from the user's setting
when he logs in, so edit "login.php", and find these lines:
$result = $db->query('SELECT id, username, password, save_pass, status FROM '.$db->prefix.'users WHERE username=\''.addslashes($form_username).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
list($user_id, $db_username, $db_password_hash, $save_pass, $status) = $db->fetch_row($result);
change them to:
$result = $db->query('SELECT id, username, password, save_pass, status, language FROM '.$db->prefix.'users WHERE username=\''.addslashes($form_username).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
list($user_id, $db_username, $db_password_hash, $save_pass, $status, $setlanguage) = $db->fetch_row($result);
find the setcookie statement:
setcookie($cookie_name, serialize(array($db_username, $form_password_hash)), $expire, $cookie_path, $cookie_domain, $cookie_secure);
and add this line below it:
setcookie($cookie_name.'_lang', $setlanguage, $expire, $cookie_path, $cookie_domain, $cookie_secure);
in "lang/??common.php" language files, two new strings need to be
added at the end of the "Stuff for the navigator" section:
'Language' => 'Language',
'Language info' => 'Select the language in which you wish to browse this forum.',
a user that isn't logged in (Guest), will have a language selection
button in their navigation bar - edit "functions.php" and find the
global statement in function generate_navlinks:
global $pun_config, $lang_common, $cookie, $cur_user;
add $languages to it:
global $pun_config, $lang_common, $cookie, $cur_user, $languages;
find this statement:
return implode(' | ', $links);
and add this code just above it:
if (isset($languages))
$links[] = '<a href="language.php">'.$lang_common['Language'].'</a>';
"language.php" is a new script, copy the included file.
Here's the source for the "language.php":
<?php
/***********************************************************************
Copyright (C) 2002, 2003, 2004 Rickard Andersson (rickard@punbb.org)
This file is part of PunBB.
PunBB is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PunBB is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
$pun_root = './';
require $pun_root.'include/common.php';
// Load the common.php language file
require $pun_root.'lang/'.$language.'/'.$language.'_common.php';
// Switch language:
if (strlen($_GET['set_lang']) > 0)
{
setcookie($cookie_name.'_lang', $_GET['set_lang'], $expire, $cookie_path, $cookie_domain, $cookie_secure);
if (!$cookie['is_guest'])
$db->query('UPDATE '.$db->prefix.'users SET language="'.$_GET['set_lang'].'" WHERE id='.$cur_user['id']) or error('Unable to update user language setting', __FILE__, __LINE__, $db->error());
redirect('language.php', 'Switching to your selected language...');
}
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Language'];
require $pun_root.'header.php';
?>
<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td> </td></tr></table>
<form method="get" action="language.php">
<table class="punmain" cellspacing="1" cellpadding="4">
<tr class="punhead">
<td class="punhead"><?php echo $lang_common['Language'] ?></td>
</tr>
<tr>
<td class="puncon2cent">
<?php
echo $lang_common['Language info'].'<br><br>';
echo '<select name="set_lang">';
if (isset($_COOKIE[$cookie_name.'_lang']))
$current = $_COOKIE[$cookie_name.'_lang'];
else
$current = '';
foreach($languages as $langid => $langname)
{
echo '<option'.($current==$langid ? ' selected' : '').' value="'.$langid.'">'.$langname.'</option>';
}
echo '</select>';
?>
<br><br>
<input type="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="4" accesskey="s">
</td>
</tr>
</table>
</form>
<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td> </td></tr></table>
<?php
require $pun_root.'footer.php';