87 lines
2.2 KiB
PHP
87 lines
2.2 KiB
PHP
<?php
|
|
/***************************************************************************
|
|
* For license information see doc/license.txt
|
|
*
|
|
* Unicode Reminder メモ
|
|
***************************************************************************/
|
|
|
|
class translate
|
|
{
|
|
/* translate the given string
|
|
*/
|
|
function t($message, $style, $resource_name, $line, $plural='', $count=1, $lang=null)
|
|
{
|
|
global $opt;
|
|
|
|
if ($message == '')
|
|
return '';
|
|
|
|
if ($plural != '' && $count!=1)
|
|
$message = $plural;
|
|
$search = $this->prepare_text($message);
|
|
|
|
if (($lang === null) || ($lang == $opt['template']['locale']))
|
|
$trans = gettext($search);
|
|
else
|
|
{
|
|
// do not use sql_value(), as this is also used from lib1
|
|
$rs = sql("SELECT IFNULL(`sys_trans_text`.`text`, '&3')
|
|
FROM `sys_trans`
|
|
LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'
|
|
WHERE `sys_trans`.`text`='&2' LIMIT 1", $lang, $search, $message);
|
|
if ($r = sql_fetch_array($rs))
|
|
$trans = $r[0];
|
|
else
|
|
$trans = '';
|
|
sql_free_result($rs);
|
|
}
|
|
|
|
// safe w/o mb because asc(%) < 128
|
|
if (strpos($trans, "%")>=0)
|
|
$trans = $this->v($trans);
|
|
|
|
return $trans;
|
|
}
|
|
|
|
/* strip whitespaces
|
|
*/
|
|
protected function prepare_text($text)
|
|
{
|
|
$text = mb_ereg_replace("\t", ' ', $text);
|
|
$text = mb_ereg_replace("\r", ' ', $text);
|
|
$text = mb_ereg_replace("\n", ' ', $text);
|
|
while (mb_strpos($text, ' ') !== false)
|
|
$text = mb_ereg_replace(' ', ' ', $text);
|
|
|
|
return $text;
|
|
}
|
|
|
|
function v($message)
|
|
{
|
|
if ($message)
|
|
{
|
|
global $translationHandler;
|
|
global $opt;
|
|
|
|
if ($translationHandler === null) {
|
|
$translationHandler = new TranslationHandler();
|
|
}
|
|
|
|
if (!isset($language))
|
|
{
|
|
global $locale;
|
|
|
|
$language = $locale;
|
|
}
|
|
|
|
$variables = array();
|
|
$language_lower = mb_strtolower($language);
|
|
$translationHandler->loadNodeTextFile($variables, $opt['logic']['node']['id'].'.txt', $language_lower);
|
|
$translationHandler->loadNodeTextFile($variables, $opt['logic']['node']['id'].'-'.$language_lower.'.txt', $language_lower);
|
|
$message = $translationHandler->substitueVariables($variables, $language_lower, $message);
|
|
}
|
|
|
|
return $message;
|
|
}
|
|
}
|