java的资源文件一个设计目的就是方便的提供多语言支持,可是它本身对unicode的支持是十分搞笑的。很多人见到这样的资源文件都会觉得很熟悉吧:
tongren.oa.system.user.usernameexists=/u7528/u6237/u540d/u5df2/u7ecf/u5b58/u5728/uff0c/u8bf7/u91cd/u65b0/u9009/u62e9/u4e00/u4e2a/u7528/u6237/u540d
tongren.oa.system.role.rolenameexists=/u89d2/u8272/u540d/u5df2/u7ecf/u5b58/u5728/uff0c/u8bf7/u91cd/u65b0/u9009/u62e9/u4e00/u4e2a/u89d2/u8272/u540d
tongren.oa.system.role.userassignedtorole=/u6307/u5b9a/u89d2/u8272/u4e0d/u80fd/u5220/u9664/uff0c/u56e0/u4e3a/u7528/u6237{0}/u62e5/u6709/u8fd9/u4e2a/u89d2/u8272
我的天,这要怎么读?还要用工具把它转回unicode才能看到汉字,修改完了还要转回去?
昨天下午抽了一点时间写了一个hta工具来编辑资源文件,现在终于可以直接修改,自动转换保存了。直接把下面的代码保存为一个后缀为hta的文件即可:
<html>
<head>
<title></title>
</head>
<body>
<input type=file onchange="getfile()" id=fileselector>
<script language="javascript">
<!--
var fso;
var openfileforreading = 1
var openfileforwriting = 2
var openfileforappending = 8
var srcfilepath="";
fso = new activexobject("scripting.filesystemobject");
function getfile(){
if (!fso.fileexists(fileselector.value)){
alert("指定文件不存在或已经被移除");
event.returnvalue=false;
return;
}
srcfilepath = fileselector.value;
var textstream = fso.opentextfile(srcfilepath, openfileforreading,true);
viewer.value = textstream.readall();
textstream.close();
document.getelementsbyname("showtype")[0].checked=true;
buttonsaveas.disabled=false;
buttonsave.disabled=false;
}
function showastext(){
document.getelementsbyname("showtype")[1].checked=true;
viewer.value = unescape(viewer.value.replace(///u/g,"%u"))
}
function showasproperties(){
document.getelementsbyname("showtype")[0].checked=true;
viewer.value = unescape(escape(viewer.value).replace(/%u/g,"//u"))
}
function savefile(){
showasproperties();
var filestillexists = fso.fileexists(srcfilepath);
if (filestillexists)
fso.copyfile (srcfilepath,fileselector.value+".bak");
var textstream = fso.opentextfile(srcfilepath, openfileforwriting,true);
textstream.write(viewer.value);
textstream.close();
alert("资源文件已经成功保存"+(filestillexists?(",原来的文件备份为/n"+srcfilepath+".bak"):"!"));
}
function saveas(){
showasproperties();
var srcfilename = srcfilepath.substr(srcfilepath.lastindexof("//")+1);
var newfilename = prompt("请输入新文件名",srcfilename);
var newfilepath = srcfilepath.replace(srcfilename,newfilename);
if (srcfilename == newfilename){
if (confirm("您确认要覆盖原来的文件?")) savefile();
}else if (fso.fileexists(newfilepath)){
if (confirm("您确认要覆盖文件"+newfilepath+"?")) {
var textstream = fso.opentextfile(newfilepath, openfileforwriting,true);
textstream.write(viewer.value);
textstream.close();
srcfilepath = newfilepath;
alert("资源文件已经成功保存")
}
}else {
var textstream = fso.opentextfile(newfilepath, openfileforwriting,true);
textstream.write(viewer.value);
textstream.close();
fileselector = fileselector.value;
srcfilepath = newfilepath;
alert("资源文件已经成功保存")
}
}
setinterval("document.title='当前文件:'+srcfilepath",500);
//-->
</script>
<textarea id=viewer style="width:90%;height:90%"></textarea>
<br>
<span onclick="showasproperties()">
<input type=radio name="showtype">资源文件格式
</span>
<span onclick="showastext()">
<input type=radio name="showtype">文本格式
</span>
<input type=button value="保存文件" onclick="savefile()" id=buttonsave disabled>
<input type=button value="另存为文件" onclick="saveas()" id=buttonsaveas disabled>
</body>
</html>
闽公网安备 35060202000074号