2核1G3M服务器88一季度

腾讯云,阿里云百度云等 折扣价→点我←

Discuz X 语言包提取工具 discuz 教程

公共账号 管理员组

<?php
/**
 * Name: X1语言包提取工具
 * Author: Monkey && Kookxiang
 * Date: 2009/5/22 17:10:03
 * 修改后的模版放置到 template_pub 语言包,语言包放置到 data/plugindata/$plugin.lang.php 里
 * 代码中的语言包放置到 script_pub,请手动修改提取结果。
 */
@$plugin = $_POST['plugin'] ? $_POST['plugin'] : $_GET['plugin'];
echo <<<EOF
<form method="post" action="">
Plugin folder: <input type="text" name="plugin" /><input type="submit" />
</form>
EOF;
if(!$plugin) exit();

$path = $plugin.'/template/';
$pathpub = $plugin.'/template_pub/';
$phppub = $plugin.'/script_pub/';
@mkdir($phppub, 777);

$langs = array();
$d = dir($plugin);

while(false !== ($entry = $d->read())) {
	$file = pathinfo($entry);
	$extend = explode("." , $entry);
	$va = count($extend)-1;
	if($extend[$va] == 'php') {
		$c = file_get_contents($plugin.'/'.$entry);
		$c = preg_replace('/(showmessage|cpmsg)\("[\xA0-\xFF]+[^"]+[\xA0-\xFF<>\.]+"/e', 'returnstr_php(\'\0\', "$file[basename]","\1")', $c);
		$c = preg_replace("/(showmessage|cpmsg)\('[\xA0-\xFF]+[^']*[\xA0-\xFF<>\.]+'/e", 'returnstr_php(\'\0\', "$file[basename]","\1")', $c);
		$c = preg_replace('/"[\xA0-\xFF]+[^"]+[\xA0-\xFF<>\.]+"/e', 'returnstr_php(\'\0\', "$file[basename]")', $c);
		$c = preg_replace("/'[\xA0-\xFF]+[^']+[\xA0-\xFF<>\.>]+'/e", 'returnstr_php(\'\0\', "$file[basename]")', $c);
		$c = preg_replace('/[\xA0-\xFF]+[\xA0-\xFFa-zA-Z0-9,<>\.\s]*[\xA0-\xFF]+/e', 'returnstr_php(\'\0\', "$file[basename]")', $c);
		file_put_contents($phppub.$entry, $c);
	}
}

$vs = var_export($langs, 1);

$langs = array();
if (file_exists($path)){
	@mkdir($pathpub, 777);
	$d = dir($path);
	while(false !== ($entry = $d->read())) {
		$file = pathinfo($entry);
		if($file['extension'] == 'htm') {
			$c = remark(file_get_contents($path.$entry));
			$c = preg_replace('/[\xA0-\xFF]+[\xA0-\xFFa-zA-Z0-9,\.\s]*[\xA0-\xFF]+/e', 'returnstr(\'\0\', "$file[basename]")', $c);
			file_put_contents($pathpub.$entry, $c);
		}
	}
}
$vt = var_export($langs, 1);

$s = <<<EOF
<?php

\$scriptlang['$plugin'] = $vs;

\$templatelang['$plugin'] = $vt;

?>
EOF;

file_put_contents('../../data/plugindata/'.$plugin.'.lang.php', $s);
echo 'Plugin "'.$plugin.'": Done!';
function returnstr($s, $basename) {
	global $langs, $plugin, $filec;
	@$c = ++$filec[$basename];
	$key = str_replace('.', '_', $basename).'_'.$c;
	if(in_array($s, $langs)) {
		$lang_flip = array_flip($langs);
		$key = $lang_flip[$s];
	} else {
		$langs[$key] = $s;
	}
	return '{lang '.$plugin.':'.$key.'}';
}
function returnstr_php($s, $basename, $function="") {
	global $langs, $plugin, $filec;
	@$c = ++$filec[$basename];
	$key = str_replace('.', '_', $basename).'_'.$c;
	if(in_array($s, $langs)) {
		$lang_flip = array_flip($langs);
		$key = $lang_flip[$s];
	} else {
		$langs[$key] = $s;
	}
	if ($function){
		return $function.'("'.$plugin.':'.$key.'"';
	}
	return 'lang("plugin/'.$plugin.'","'.$key.'")';
}

function remark($buf) {
	$remark = array(
		array('//note', "\r\n"),
		array('/*', '*/'),
	);
	foreach($remark as $v) {			
		$data = '';
		while(count($strcut = explode($v[0], $buf, 2)) > 1) {
			$data .= $strcut[0];
			if(($strcut = explode($v[1], $strcut[1], 2)) > 1) {
				$data = preg_replace('/[\t ]+$/', '', $data);
				$data = preg_replace('/\r\n$/', '', $data);
				if($v[1] == "\r\n") {
					$buf = "\r\n";	
				} else {
					$buf = '';
				}
				$buf .= $strcut[1];
			} else {
				$buf = $strcut[0];
				break;
			}
		}
		$data .= $strcut[0];
		$buf = $data;
	}
	return $buf;
}

?>

下载地址(点击数字即可下载)→:15572


来自建站学习研究资源开放平台【bbs.zhanzhangwo.com
站长窝论坛版权声明 1、本帖标题:Discuz X 语言包提取工具
2、论坛网址:站长窝论坛
3、站长窝论坛的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
4、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
5、站长窝论坛一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本帖由公共账号在站长窝论坛《程序综合区》版块原创发布, 转载请注明出处!
评论
最新回复 (0)
返回
发新帖