Skip to content

Commit

Permalink
1,现在翻译器重载会记忆页面了
Browse files Browse the repository at this point in the history
2,修正谷歌翻译转发ui
3,额外修正原生{} => { }防止多标问题
4,翻译后自动使用pangujs
5,转义&
  • Loading branch information
yunzlp committed Mar 13, 2024
1 parent cb974c7 commit fcd68df
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
1 change: 1 addition & 0 deletions GameMakerManualTranslator-Project/default.aproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<folder name="资源文件" path="res" embed="true" local="false" ignored="false">
<file name="翻译.aardio" path="res\翻译.aardio" comment="res\翻译.aardio"/>
<file name="热键设置.aardio" path="res\热键设置.aardio" comment="res\热键设置.aardio"/>
<file name="函数.aardio" path="res\函数.aardio" comment="res\函数.aardio"/>
</folder>
<folder name="窗体文件" path="dlg" comment="目录" embed="true"/>
</project>
25 changes: 8 additions & 17 deletions GameMakerManualTranslator-Project/main.aardio
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,14 @@ mainForm.add()
import console
import fsys;

loadcodex("\res\函数.aardio");


//取启动参数
arg=_ARGV[1]
arg=arg_path(arg)

//去除多余斜杠和多余协议头
if ( arg!=null ){
arg=string.replace(arg,"/","")
arg=string.match(arg,"<@gmmt:@>(.*)")
}

//尝试补正#
if ( arg!=null ){
arg=string.replace("#"+arg,"#+","#")
//console.log(arg)
//gmmt://#t=GameMaker_Language%2FGML_Reference%2FAsset_Management%2FSequences%2FSequences.htm
}else{
arg=""
}
f5=true

robohelp=//GMS2-Robohelp-en
mainfile=//index.htm
Expand Down Expand Up @@ -73,7 +62,9 @@ if setting.group{
//当目录出现变更,直接一个刷的新
import fsys.dirWatcher;
win.thrdWatcher = fsys.dirWatcher.thread(function(filename,action,actionText){
f5=false
f5=true
arg=theView.eval('document.location.hash')
arg=arg_path("gmmt://"+arg)
}, path+"/patch");

loadcodex("\res\翻译.aardio");
Expand All @@ -90,8 +81,8 @@ theView.enableDefaultContextMenus(false)
mainForm.setInterval(100,function(){
try{
//刷新加载
if !f5{
f5=true
if f5{
f5=false
theView.go(mainPath+arg)
arg=""
}
Expand Down
17 changes: 17 additions & 0 deletions GameMakerManualTranslator-Project/res/函数.aardio
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
arg_path=function(arg){
//去除多余斜杠和多余协议头
if ( arg!=null ){
arg=string.replace(arg,"/","")
arg=string.match(arg,"<@gmmt:@>(.*)")
}

//尝试补正#
if ( arg!=null ){
arg=string.replace("#"+arg,"#+","#")
//console.log(arg)
//gmmt://#t=GameMaker_Language%2FGML_Reference%2FAsset_Management%2FSequences%2FSequences.htm
}else{
arg=""
}
return arg
}
Binary file modified GameMakerManualTranslator.exe
Binary file not shown.
33 changes: 24 additions & 9 deletions patch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ $("head").append(cssHtml);
///////////////////////////////////////////////////////////////////////////////////

//移除并替换给定字符串的所有标签到{}
removeHtml=function(str){

removeHtml=function(str,isOld){
if (isOld) str=str.replaceAll("{}", "{ }");
//替换标签到{}
str=str.replace(/(<([^>]+)>)/ig, "{}");

Expand Down Expand Up @@ -79,9 +79,18 @@ qqq_ok=function(){

}

///来源预处理
qqq_translate_form_path=function(str){

//翻译前转义空格的转义
str=str.replace(/\&nbsp\;/g," ")

return str
}

qqq_translate_set=function(str){

$(".qqq_menu .new").html(str)
$(".qqq_menu .new").html(pangu.spacing(str))

qqq_hight_light()

Expand All @@ -106,23 +115,25 @@ qqq_translate_patch=function(str){
str=str.replace(/ ?;/g,";")
str=str.replace(/& ?/g,"&")

//修正&
str=str.replaceAll("&amp;","&")

return str
}

//复合翻译引擎
qqq_translate=async function (engine){
var old=$(".qqq_menu .old").html()

//翻译前转义空格的转义
old=old.replace(/\&nbsp\;/g," ")
old=qqq_translate_form_path(old)

var json=await translate(old,engine).catch((e) => {})
if(!json){alert("接口报空,请检查token")}
var str=json.data.target

//修正返回内容
str=qqq_translate_patch(str)


//console.log(str)

qqq_translate_set(str)
Expand All @@ -137,8 +148,8 @@ qqq_translate_tts=async function (is_filt){
old=old.replaceAll('{}'," ")
}

//翻译前转义空格的转义
old=old.replace(/\&nbsp\;/g," ")
old=qqq_translate_form_path(old)

var str=await translate_tts(old).catch((e) => {})
if(!str){alert("接口挂了(悲")}

Expand All @@ -155,6 +166,9 @@ qqq_translate_tts=async function (is_filt){
//谷歌转发翻译
qqq_translate_googleR=async function(){
var old=$(".qqq_menu .old").html()
old=qqq_translate_form_path(old)


$.post("http://127.0.0.1:1182",{t:old},function(data){
data=JSON.parse(data)
if (data.state!="ok") return 0
Expand Down Expand Up @@ -425,11 +439,12 @@ add_event=async function(ins,file){
//处理html标签为{}
var str=target.html()
var key=removeHtml(str)
var old=removeHtml(str,true)//额外处理{} => { }

//console.log({key:key,str:str})

$(".qqq_menu .key").val(key)
$(".qqq_menu .old").html(key)
$(".qqq_menu .old").html(old)
var ele=$(".qqq_menu .new")
ele.html(key)

Expand Down
Binary file modified 谷歌翻译转发.exe
Binary file not shown.

0 comments on commit fcd68df

Please sign in to comment.