Jamers Posted November 5, 2014 Report Share Posted November 5, 2014 IPB 3.4.7里有一些内容是在数据库内的,难道在数据库中一条条处理?NO,这不符合我们偷懒的精神,我的宗旨是宁愿麻烦一点也不愿意干繁琐重复的事(当然 汉化工作属于这一类型,但又没办法让程序处理,还是只能硬着头皮来。。),所以我喜欢在文本文件中将相关资料处理完后,再用数据库管理工具将相应资料 update进去,经过一个早晨的调试,将雏形搞出来了,在这里抛砖引玉吧。如果有更好的方式也可与我一并交流共同成长。不再废话,上代码! $def 数组为需要更新的文件中的更新字段以及定位字段。程序中默认会把空值抛弃。整个汉化流程是:将数据库中需要汉化的表导出成TEXT文件(表名.txt,带 上标题,文本内容用双引号限定),然后将相应内容汉化完后用此程序处理,处理结果显示出来后,复制网页源码到数据库管理工具中搜索update查询。这样 汉化就完成了,有可能需要更新一下缓存才能够看到喔。 <?php /** * 将IPB数据库汉化的文本文件转换成数据库update语句 * * Jamers 2014.11.02 8:23初版完成 * 2014.11.4 发现有的时候有换行符,将不匹配数据加上下一行继续匹配 */ header("Content-type: text/html; charset=utf-8"); $path = './'; $def = array( 'core_sys_settings_titles'=>array('where'=>'conf_title_keyword','update'=>'conf_title_title,conf_title_desc,conf_title_tab'), 'core_sys_conf_settings'=>array('where'=>'conf_key','update'=>'conf_title,conf_description,conf_default,conf_start_group,conf_extra') ); $out = ''; foreach ($def as $k=>$v) { $fn = $path.$k.'.txt'; if (file_exists($fn)) { $data = file($fn); //echo $data[0]; $rr = explode(',',trim($data[0])); $col_c = count($rr)-1; //$w = explode(',',$v['where']); //分隔Where //$u = explode(',',$v['update']); //分隔update $w = array(); $u = array(); $p = '/^'; foreach($rr as $m=>$x) { $n = preg_replace('/["\']/','',$x); if (preg_match("/,{$n},/i",",{$v['where']},")) { $w[$m]=$n; } if (preg_match("/,{$n},/i",",{$v['update']},")) { $u[$m]=$n; } $p .= '"(.*?)",'; } $p =substr($p,0,-1).'$/ims'; $out .= '/********************************'."Table:{$k}".'********************************/'."\r\n"; $add = false; for ($i=1;$i<=count($data)-1;$i++) { if ($add) { $tmp .= $data[$i]; } else { $tmp = $data[$i]; } //如果不匹配添加一行继续匹配 if (preg_match($p,trim($tmp),$math)) { $add = false; $res = 'update '.$k. ' set '; foreach($u as $t=>$s) { if (trim($math[$t+1])!=='') //如果为空直接跳过 $res .= "{$s}=\"{$math[$t+1]}\","; } $res = substr($res,0,-1); $res .= ' where '; foreach($w as $t=>$s) { $res .= "{$s}=\"{$math[$t+1]}\" and "; } $res = substr($res,0,-5).";"; $out .= $res."\r\n"; }else{ $add = true; } } $out .= '/*************************************************************************************/'."\r\n"; } } //echo "<textarea warp='off' cols=120 rows=40 style=\"white-space:nowrap; overflow:scroll;\">".$out."</textarea>"; echo "<pre>".htmlspecialchars($out)."</pre>"; ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now