模組:ZhConversion/data/doc

这是Module:ZhConversion/data的文档页面

繁簡轉換資料表,內容出自phab:source/mediawiki/browse/master/includes/languages/data/ZhConversion.php 本表內容經過排序。

資料更新方法

複製phab:source/mediawiki/browse/master/includes/languages/data/ZhConversion.php的程式碼,貼進以下腳本,在瀏覽器的Console模式下運行即可取得印出的Lua代碼。

rule_max_length的數值亦須同步

//此腳本執行完後會在console中印出繁簡轉換規則的Lua代碼
var rule_max_length = 6; //為了增加搜尋性能,子字串的長度需設置最大限制 (Lua運行時間有限)
var input_php = `
//請將 https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/languages/data/ZhConversion.php
//的程式碼貼進來
public const ZH_TO_HANT = [
	'㐷' => '傌',
	'㐹' => '㑶',
	'龟鉴' => '龜鑑',
	'鿒' => '鿓',
	',并力' => ',並力',
	',并力討' => ',并力討',
	',并力讨' => ',并力討',
	',个中' => ',箇中',
	];
	
	public const ZH_TO_HANS = [
	'㑯' => '㑔',
	'㑳' => '㑇',
	'蒙特內哥羅' => '黑山',
	'滑鼠' => '鼠标',
	];
}
`;
var in_2hant_regexp = /\ZH_TO_HANT[\s\n\r]*=[\s\n\r]*\[([^\]]+)\][\s\n\r]*;/;
var in_2hans_regexp = /\ZH_TO_HANS[\s\n\r]*=[\s\n\r]*\[([^\]]+)\][\s\n\r]*;/;
var in_rule_regexp = /'(([^'\\]|\\.)*)'[\s\n\r]*=>[\s\n\r]*'(([^'\\]|\\.)*)'[\s\n\r]*,/g;
var in_2hant_str = "";
var in_2hans_str = "";
input_php.replace(in_2hant_regexp,function(str, rules_str){
	in_2hant_str = rules_str;
});
input_php.replace(in_2hans_regexp,function(str, rules_str){
	in_2hans_str = rules_str;
});
in_2hant_str = in_2hant_str || "";
in_2hans_str = in_2hans_str || "";
if (in_2hant_str.trim() != '' && in_2hans_str.trim() != '') {
	var rule_2hant_input = {};
	var rule_2hans_input = {};
	
	in_2hant_str.replace(in_rule_regexp,function(str,key,no_data,value){
		rule_2hant_input[key] = value;
		return str;
	});
	in_2hans_str.replace(in_rule_regexp,function(str,key,no_data,value){
		rule_2hans_input[key] = value;
		return str;
	});
	var rule_2hant = Object.keys(rule_2hant_input).sort().reduce(
	  (obj, key) => { 
		obj[key] = rule_2hant_input[key]; 
		return obj;
	  }, 
	  {}
	);
	var rule_2hans = Object.keys(rule_2hans_input).sort().reduce(
	  (obj, key) => { 
		obj[key] = rule_2hans_input[key]; 
		return obj;
	  }, 
	  {}
	);
	var lua_rule_2hant = '';
	var lua_rule_2hans = '';
	Object.keys(rule_2hant).forEach(key => {
		if ( typeof (key) == typeof ("") ){
			if (key.length <= rule_max_length) {
				var value = rule_2hant[key];
				if (lua_rule_2hant != '') lua_rule_2hant += ',';
				lua_rule_2hant += `['${key}']='${value}'`;
			}
		}
	});
	Object.keys(rule_2hans).forEach(key => {
		if ( typeof (key) == typeof ("") ){
			if (key.length <= rule_max_length) {
				var value = rule_2hans[key];
				if (lua_rule_2hans != '') lua_rule_2hans += ',';
				lua_rule_2hans += `['${key}']='${value}'`;
			}
		}
	});
	console.log({"2hant":lua_rule_2hant, "2hans":lua_rule_2hans});
}