SugarCRM旧语言包移植到新语言包工具

1 篇文章 0 订阅
1 篇文章 0 订阅
<!DCOTYPE html>
<html>
<head>
<title>SugarCRM旧语言包移植到新语言包工具</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style>
textarea.ta{width:100%;height:50px;border:1px solid;padding:5px 10px;}
</style>
</head>
<body>
<form method="POST" οnsubmit="return predo(this);">
旧版中文语言数组<br/>
<textarea name="zh" title="格式:array(key=>val[,key=>val])" class="ta" wrap="off" ></textarea><br/>
新版英文语言数组<br/>
<textarea name="en"  title="格式:array(key=>val[,key=>val])" class="ta" wrap="off" ></textarea><br/>
<button type="submit" title="处理流程:">开始处理</button><input type="checkbox" title="框中填写的代码如果是js的对象请勾上,php会自动转换成php的array"  name="json"  />js对象
</form>
<script>
var typed = function( obj ) {
		if ( obj == null ) {
			return String( obj );
		}
		
		var class2type = {};
		var core_toString = class2type.toString;
		var t="Boolean Number String Function Array Date RegExp Object Error".split(" ");
		for (var fi = 0;fi < t.length;fi++) class2type[ "[object " + t[fi] + "]" ] = t[fi].toLowerCase();
		return typeof obj === "object" || typeof obj === "function" ?
			class2type[ core_toString.call(obj) ] || "object" :
			typeof obj;
	};
var quote = function (str) {
	var encode = /["\\\x00-\x1f]|[^\x1f-\x7f]/g,
		meta = {
			'\b': '\\b',
			'\t': '\\t',
			'\n': '\\n',
			'\f': '\\f',
			'\r': '\\r',
			'"' : '\\"',
			'\\': '\\\\'
		};
		if (str.match(encode)) {
			return '"' + str.replace(encode, function (a) {
				var c = meta[a];
				if (typeof c === 'string') {
					return c;
				}
				c = a.charCodeAt();
				return '\\u' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
			}) + '"';
		}
		return '"' + str + '"';
	};
var  var2json = function (o) {
	if (o === null) {
		return 'null';
	}

	var pairs, k, name, val,
		type = typed(o);

	if (type === 'undefined') {
		return undefined;
	}

	// Also covers instantiated Number and Boolean objects,
	// which are typeof 'object' but thanks to $.type, we
	// catch them here. I don't know whether it is right
	// or wrong that instantiated primitives are not
	// exported to JSON as an {"object":..}.
	// We choose this path because that's what the browsers did.
	if (type === 'number' || type === 'boolean') {
		return String(o);
	}
	if (type === 'string') {
		return quote(o);
	}
	if (typeof o === 'function') {
		return o.toString();
	}
	if (type === 'date') {
		var month = o.getUTCMonth() + 1,
			day = o.getUTCDate(),
			year = o.getUTCFullYear(),
			hours = o.getUTCHours(),
			minutes = o.getUTCMinutes(),
			seconds = o.getUTCSeconds(),
			milli = o.getUTCMilliseconds();

		if (month < 10) {
			month = '0' + month;
		}
		if (day < 10) {
			day = '0' + day;
		}
		if (hours < 10) {
			hours = '0' + hours;
		}
		if (minutes < 10) {
			minutes = '0' + minutes;
		}
		if (seconds < 10) {
			seconds = '0' + seconds;
		}
		if (milli < 100) {
			milli = '0' + milli;
		}
		if (milli < 10) {
			milli = '0' + milli;
		}
		return '"' + year + '-' + month + '-' + day + 'T' +
			hours + ':' + minutes + ':' + seconds +
			'.' + milli + 'Z"';
	}

	pairs = [];

	if ('array' == typed(o)) {
		for (k = 0; k < o.length; k++) {
			pairs.push(var2json(o[k]) || 'null');
		}
		return '[' + pairs.join(',') + ']';
	}

	// Any other object (plain object, RegExp, ..)
	// Need to do typeof instead of $.type, because we also
	// want to catch non-plain objects.
	var hasOwn = Object.prototype.hasOwnProperty;
	
	if (typeof o === 'object') {
		for (k in o) {
			// Only include own properties,
			// Filter out inherited prototypes
			if (hasOwn.call(o, k)) {
				// Keys must be numerical or string. Skip others
				type = typeof k;
				if (type === 'number') {
					name = '"' + k + '"';
				} else if (type === 'string') {
					name = quote(k);
				} else {
					continue;
				}
				type = typeof o[k];

				// Invalid values like these return undefined
				// from toJSON, however those object members
				// shouldn't be included in the JSON string at all.
				if (type !== 'function' && type !== 'undefined') {
					val = var2json(o[k]);
					pairs.push(name + ':' + val);
				}
			}
		}
		return '{' + pairs.join(',') + '}';
	}
}
	
var json2var = function( data ) {
	// Attempt to parse using the native JSON parser first
	if ( window.JSON && window.JSON.parse ) {
		return window.JSON.parse( data );
	}

	if ( data === null ) {
		return data;
	}

	if ( typeof data === "string" ) {

		// Make sure leading/trailing whitespace is removed (IE can't handle it)
		data = data.replace(/^\s+|\s+$/g, '');

		if ( data ) {
			var rvalidchars = /^[\],:{}\s]*$/,
				rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
				rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,
				rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
			// Make sure the incoming data is actual JSON
			// Logic borrowed from http://json.org/json2.js
			if ( rvalidchars.test( data.replace( rvalidescape, "@" )
				.replace( rvalidtokens, "]" )
				.replace( rvalidbraces, "")) ) {

				return ( new Function( "return " + data ) )();
			}
		}
	}

	alert( "Invalid JSON: " + data );
};

function predo(f) {
	var zh = f.elements.zh.value;
	var en = f.elements.en.value;
	var json = f.elements.json.checked;
	
	if (/^\s*$/.test(zh)) return alert('请输入旧版本中文语言数组代码'),false;
	if (/^\s*$/.test(en)) return alert('请输入新版本英文语言数组代码'),false;
	
	if (json) {
		try {
			zh = ( new Function( "return " + zh) )();
			f.elements.zh.value = var2json(zh);
		} catch (e) {
			return alert('旧版本中文语言数组代码是错误的js代码:' +(e.message||e)),false;
		}
		try {
			en = ( new Function( "return " + en) )();
			f.elements.en.value = var2json(en);
		} catch (e) {
			return alert('新版本英文语言数组代码是错误的js代码:' +(e.message||e)),false;
		}
		
		var is_array = function(i){return 'array' == typed(i);};
		var is_object = function(i){return 'object' == typed(i);};
		var isset = function(i){return 'undefined' != typed(i);};
		var is_string = function(i){return 'string' == typed(i);};
		var FOR = function(o,func){
			if ('array' == typed(o)) for (var fi = 0;fi < o.length;fi++) func.call(o[fi],fi,o[fi]);
			else if ('object' == typed(o)) for (var fi in o) func.call(o[fi],fi,o[fi]);
			else func.call(o,0, o);
		};
		var arrayFor = function($zh,$en){//递归处理语言数组,存在相同主键就移植到en数组中,没有保留en原有英文
			var $rea = is_array($en) ? [] : {};
			
			FOR ($en, function($k,$v){
				if (is_string($v)) {
					$rea[$k] = isset($zh[$k])? $zh[$k] : $v;
				} else if (is_array($v) ) {
					$rea[$k] = isset($zh[$k]) && is_array($zh[$k]) ?arrayFor($zh[$k],$v) :$v;
				} else if (is_object($v) ) {
					$rea[$k] = isset($zh[$k]) && is_object($zh[$k]) ?arrayFor($zh[$k],$v) :$v;
				} else {
					$rea[$k] = isset($zh[$k]) && !is_array($zh[$k])? $zh[$k] : $v;
				}
			});
			
			return $rea;
		}
		
		var out = var2json(arrayFor(zh,en));
		document.getElementById('out').innerHTML = '处理后数组<br/><textarea wrap="off" class="ta">'+(out ? out.replace(/[<>]/g, function($0){return '<' == $0 ? '<' :'>';}) : '') +'</textarea><br/>';
		return false;//json,直接使用js处理
	}
	//return false;
};
</script>
<div id="out">
<?php
define('sugarEntry', 1);

function userErrorHandler() {
    $e = func_get_args();
    echo '<pre style="color:red;"><br/>----------运行出错---------:<br/>'.print_r($e, 1).'<br/>----------运行出错---------<br/></pre>';
}
set_error_handler("userErrorHandler");
set_exception_handler("userErrorHandler");

function shutdown() {
    $a=error_get_last();    
    if($a != null) echo '<pre style="color:red;"><br/>++++++低级错误+++++<br/>'.print_r($a, 1).'<br/>++++++低级错误+++++<br/></pre>';   
} 

register_shutdown_function('shutdown');//如果使用了exit将不运行此脚本


//语言包数组处理
if (!empty($_POST)) {
	$zh = $_POST['zh'];
	$en = $_POST['en'];
	$json = isset($_POST['json']);
	
	if ($json) {
		$zh = json_decode($zh, 1);
		$en = json_decode($en, 1);
	} else {
		eval('$zh = '.$zh.';');
		eval('$en = '.$en.';');
	}

	if (!is_array($zh) || !is_array($en)) {
		echo '数组文件非法内容:'.$_POST['zh'].'='.gettype($zh).';'.$_POST['en'].'='.gettype($en);
	} else {
		$newEn = arrayFor($zh,$en);
		echo '处理后数组<br/><textarea wrap="off" class="ta">'.htmlspecialchars ($json?json_encode($newEn) :var_export($newEn,1)).'</textarea><br/>' ;
	}
}

function arrayFor($zh,$en){//递归处理语言数组,存在相同主键就移植到en数组中,没有保留en原有英文
	$rea = array();
	
	foreach ($en as $k => $v) {
		if (is_array($v)) {
			$rea[$k] = isset($zh[$k]) && is_array($zh[$k]) ?arrayFor($zh[$k],$v) :$v;
		} else {
			$rea[$k] = isset($zh[$k]) && !is_array($zh[$k])? $zh[$k] : $v;
		}
	}
	
	return $rea;
}
?>
</div>
</body>
</html>


php的array处理


结果

array (
  'a' => '是a',
  'b' => '是b',
  'c' => '是c',
  'd' => 
  array (
    'dd' => 'kkk',
    'ddd' => 'is ddd',
  ),
  'e' => 'is e',
)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,感谢 索孚方科 公司的大力支持以及相关研发人员的鼎力协助,让山寨版的CE语言可能比Pro版的更贴切好用一些,故本语言也可以说攀了个粗腿。对公司相关人员快捷高效的测试,表示感谢! 其次,注意事项: 兼容6.5.X; 一般注意事项,见http://down.51cto.com/data/275922 建议中文的sugar系统修改config.php配置文件,以获得更好使用(先备份好原文 件)。 config.php为sugar配置文件,建议更改部分。 第1处: 'default_currency_iso4217' => 'CNY', //修改默认货币代码为人民币 'default_currency_name' => 'Chinese Yuan', //修改默认货币名称为元,可在 系统管理->货币 下增加汇率和其他货币 第2处: 'default_language' => 'zh_cn', //修改默认登陆为中文 第3处: 'default_locale_name_format' => 's f l', //姓名称谓 第4处: 'default_charset' => 'EUC-CN', //导入导出为GB2312格式,避免中文乱码 第5处,可不变: 'upload_dir' => 'upload/', //保持此目录或者修改上传目录,括document的文件附件存放在此目录 'upload_maxsize' => 30000000, //保持或者修改此值,修改单个文件最大上传值(默认30M) =========================================================================== 本次语言解决的一些问题: 1.在IE下的Ajax问题(模块因语言问题显示null),详见《6.4.3中文模块列表不能正确显示?寻帮助》一文http://www.sugar360.cn/forum.php ... &extra=page=1 2.已解决:模块生成器->文件-> 可用子面板->默认,点开后无内容(而英文下无此问题); 3.中文下,日历的日期与星期几可能不对应的问题; 4.更翻译,让其更加易懂。 5.相关翻译人员:木子飞飞 ([email protected]),无常([email protected]),Cheli Zhao ([email protected]), Richard Qi ([email protected])。 6.若对翻译的一些文字有建议,可直接联系我:[email protected] 14:52 2014-7-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值