<?php
///////////////////////////////////////////////////////////////////////////////
// Script to help translation of phpBB 2.0 language files
// Copyright 2002 Matthijs < phpbb@matthijs.net >
// Version 1.1.0
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Customize these variables to your situation
///////////////////////////////////////////////////////////////////////////////
$phpbb_root_path = "./";
$phpEx = "php";
$translate_from = "english";
$translate_to = "dutch";
// at present only 'main' and 'admin' are supported
$translate_file = "main";
$input_size = "70";
///////////////////////////////////////////////////////////////////////////////
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>phpBB 2.0 Language translation tool</TITLE></HEAD>
<STYLE type="text/css">
body { background-color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; }
TD { border: #000000; border-style: solid; border-left-width: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; font-size: 10pt; }
textarea { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; }
input { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; }
TR.red { background-color: red; }
H1 { font-size: 14pt; font-weight: bold; }
</STYLE>
<BODY>
<center><H1>phpBB 2.0 Language Translation Tool</H1></center>
<?php
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
//
// addslashes to vars if magic_quotes_gpc is off
//
if( !get_magic_quotes_gpc() )
{
if( is_array($HTTP_POST_VARS) )
{
while( list($k, $v) = each($HTTP_POST_VARS) )
{
if( is_array($HTTP_POST_VARS[$k]) )
{
while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
{
$HTTP_POST_VARS[$k][$k2] = addslashes($v2);
}
@reset($HTTP_POST_VARS[$k]);
}
else
{
$HTTP_POST_VARS[$k] = addslashes($v);
}
}
@reset($HTTP_POST_VARS);
}
}
if ( !isset($HTTP_POST_VARS['submit']) )
{
// Get language to translate to, doesn't need to exist
if (@file_exists($phpbb_root_path . 'language/lang_' . $translate_to . '/lang_' . $translate_file . '.' . $phpEx))
{
include($phpbb_root_path . 'language/lang_' . $translate_to . '/lang_' . $translate_file . '.' . $phpEx);
}
$lang_to = $lang;
unset($lang);
// Get language te translate from
if (@file_exists($phpbb_root_path . 'language/lang_' . $translate_from . '/lang_' . $translate_file . '.' . $phpEx))
{
include($phpbb_root_path . 'language/lang_' . $translate_from . '/lang_' . $translate_file . '.' . $phpEx);
$lang_from = $lang;
}
else
{
die ("Can't find language file ($translate_from)");
}
print "<form method=\"post\">";
print "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">";
@reset($lang_from);
while ( list($key, $value) = each($lang_from) )
{
if ( is_array($value) )
{
while ( list($key2, $value2) = each($value) )
{
$value2 = htmlspecialchars($value2);
$translation = htmlspecialchars($lang_to["$key"]["$key2"]);
$name = $key . "__" . str_replace('.', '_', $key2);
$class = ($translation != '' ? '' : ' class="red"');
print "<tr".$class."><td width=\"50%\" valign=\"top\">$value2</td><td valign=\"top\" width=\"50%\"><input type=\"text\" size=\"$input_size\" name=\"$name\" value=\"$translation\"></td></tr>\n";
}
}
else
{
$value = htmlspecialchars($value);
$value = str_replace("<br />", "<br /><br />", $value);
$strlen = ($lang_to[$key] != "" ? strlen($lang_to[$key]) : strlen($value));
$rows = floor($strlen / $input_size) + 1;
$translation = htmlspecialchars($lang_to["$key"]);
$class = ($translation != '' ? '' : ' class="red"');
if ( $rows > 1 )
{
print "<tr".$class."><td width=\"50%\" valign=\"top\">$value</td><td valign=\"top\" width=\"50%\"><textarea rows=\"$rows\" cols=\"$input_size\" name=\"$key\">$translation</textarea></td></tr>\n";
}
else
{
print "<tr".$class."><td width=\"50%\" valign=\"top\">$value</td><td valign=\"top\" width=\"50%\"><input type=\"text\" size=\"$input_size\" name=\"$key\" value=\"$translation\"></td></tr>\n";
}
}
flush();
}
print "</table>";
print "<br><center><input type=\"submit\" name=\"submit\" value=\"Submit\"></center>";
print "</form>";
}
else
{
$file = file($phpbb_root_path . 'language/lang_' . $translate_from . '/lang_' . $translate_file . '.' . $phpEx);
$file_text = implode('', $file);
while (list($key, $value) = each($HTTP_POST_VARS))
{
if ($key != 'submit')
{
if ( strpos($key, '__') )
{
list($first, $second) = explode('__', $key);
$second = str_replace('_', '.', $second);
$variable = "\$lang['$first']['$second']";
}
else
{
$variable = "\$lang['$key']";
}
$variable = preg_quote($variable);
$search = "/(".$variable.") \=[ ]+'(.*)';/";
$file_text = preg_replace($search, "\\1 = '$value';", $file_text);
}
}
print "<textarea cols=100 rows=35 wrap=off>$file_text</textarea>\n";
print "<br><br>Copy-paste all text above into notepad, save it and upload to the right dir.";
}
?>
</BODY>
</HTML>