From 79acc0e8e7c3b2f07941476321871c86a4363581 Mon Sep 17 00:00:00 2001 From: xulihang Date: Sun, 31 Mar 2019 16:45:45 +0800 Subject: [PATCH] add note and creation info for tmx export and import; apply extra info when applying a tm --- BasicCAT/BasicCAT.b4j | 105 ++++++++++++++-------------- BasicCAT/BasicCAT.b4j.meta | 2 +- BasicCAT/Project.bas | 92 +++++++++++++++++------- BasicCAT/TM.bas | 12 +++- BasicCAT/TMManager.bas | 2 + BasicCAT/TMX.bas | 70 +++++++++++++++++-- BasicCAT/confirmReviewDialog.bas | 4 +- BasicCAT/searchAndReplaceDialog.bas | 4 +- 8 files changed, 201 insertions(+), 90 deletions(-) diff --git a/BasicCAT/BasicCAT.b4j b/BasicCAT/BasicCAT.b4j index 60aef0a..a5923bd 100644 --- a/BasicCAT/BasicCAT.b4j +++ b/BasicCAT/BasicCAT.b4j @@ -169,57 +169,57 @@ Library8=jrandomaccessfile Library9=jb4xencryption Module1=FileChooserUtils Module10=preTranslateDialog -Module11=SearchView -Module12=TMManager -Module13=importDialog -Module14=idmlFilter -Module15=Xml2Map -Module16=XMLUtils -Module17=Utils -Module18=TMX -Module19=searchAndReplaceDialog +Module11=zip4j +Module12=progressDialog +Module13=SearchView +Module14=TMManager +Module15=importDialog +Module16=idmlFilter +Module17=Xml2Map +Module18=XMLUtils +Module19=Utils Module2=Project -Module20=xliffFilter -Module21=Preferences -Module22=ITP -Module23=AutoSaver -Module24=icu4j -Module25=tikal -Module26=PDF2TXT -Module27=FileUtils -Module28=Map2Xml -Module29=MT +Module20=TMX +Module21=searchAndReplaceDialog +Module22=xliffFilter +Module23=Preferences +Module24=ITP +Module25=AutoSaver +Module26=icu4j +Module27=tikal +Module28=PDF2TXT +Module29=FileUtils Module3=segmentation -Module30=SRX -Module31=POIWord -Module32=pdfbox -Module33=git -Module34=dictWebView -Module35=InputTextAreaBox -Module36=FontPicker -Module37=TermEditor -Module38=TermManager -Module39=HistoryViewer +Module30=Map2Xml +Module31=MT +Module32=SRX +Module33=POIWord +Module34=pdfbox +Module35=git +Module36=dictWebView +Module37=InputTextAreaBox +Module38=FontPicker +Module39=TermEditor Module4=CustomListView -Module40=HistoryRecord -Module41=Previewer -Module42=ClientKVS -Module43=statistics -Module44=LanguageTool -Module45=confirmReviewDialog -Module46=LanguagePairSelector -Module47=idmlUtils -Module48=editDistance -Module49=InputBox +Module40=TermManager +Module41=HistoryViewer +Module42=HistoryRecord +Module43=Previewer +Module44=ClientKVS +Module45=statistics +Module46=LanguageTool +Module47=confirmReviewDialog +Module48=LanguagePairSelector +Module49=idmlUtils Module5=txtFilter -Module50=MTParamsFiller -Module51=progressDialog -Module52=filterGenericUtils -Module53=TBX -Module54=CallSubUtils -Module55=viewSegment -Module56=serverLauncher -Module57=zip4j +Module50=editDistance +Module51=InputBox +Module52=MTParamsFiller +Module53=filterGenericUtils +Module54=TBX +Module55=CallSubUtils +Module56=viewSegment +Module57=serverLauncher Module58=languageChooser Module59=TMEditor Module6=TM @@ -711,9 +711,12 @@ Sub fillWithTM Log(LastException) Return End Try - Dim targetTextArea As TextArea - targetTextArea=pane.GetNode(1) - targetTextArea.Text=tmTableView.SelectedRowValues(2) + Dim translation As String=tmTableView.SelectedRowValues(2) + currentProject.setTranslation(currentProject.lastEntry,translation,True) + currentProject.fillOne(currentProject.lastEntry,translation) + 'Dim targetTextArea As TextArea + 'targetTextArea=pane.GetNode(1) + 'targetTextArea.Text=translation currentProject.contentIsChanged End If End If @@ -1021,7 +1024,7 @@ Sub exportTMXMi_Action Dim translation As String translation=targetMap.Get("text") bitext.Add(translation) - + bitext.Add(targetMap) segments.Add(bitext) Next Dim result As Int diff --git a/BasicCAT/BasicCAT.b4j.meta b/BasicCAT/BasicCAT.b4j.meta index 5e28723..204514d 100644 --- a/BasicCAT/BasicCAT.b4j.meta +++ b/BasicCAT/BasicCAT.b4j.meta @@ -188,4 +188,4 @@ ModuleClosedNodes7= ModuleClosedNodes8= ModuleClosedNodes9= SelectedBuild=0 -VisibleModules=1,2,3,4,5,6,7,8,9,10,57,51 +VisibleModules=1,2,3,4,5,6,7,8,9,10,20,14,21,47 diff --git a/BasicCAT/Project.bas b/BasicCAT/Project.bas index e1b0a65..d890119 100644 --- a/BasicCAT/Project.bas +++ b/BasicCAT/Project.bas @@ -1761,16 +1761,7 @@ Public Sub fillPane(FirstIndex As Int, LastIndex As Int) addTextAreaToSegmentPane(segmentPane,bitext.Get(0),bitext.Get(1)) Dim extra As Map extra=bitext.Get(4) - If extra.ContainsKey("neglected") Then - If extra.Get("neglected")="yes" Then - Utils.disableTextArea(segmentPane) - End If - End If - If extra.ContainsKey("note") Then - If extra.Get("note")<>"" Then - CSSUtils.SetStyleProperty(segmentPane.GetNode(1),"-fx-background-color","green") - End If - End If + setPaneStatus(extra,segmentPane) If Main.calculatedHeight.ContainsKey(bitext.Get(0)&" "&bitext.Get(1)) Then Dim h As Int=Main.calculatedHeight.Get(bitext.Get(0)&" "&bitext.Get(1)) Main.setLayout(segmentPane,i,h) @@ -1828,14 +1819,14 @@ Sub preTranslate(options As Map) Log(similarity>=matchrate) If similarity>=matchrate Then - setTranslation(index,resultList.Get(2)) + setTranslation(index,resultList.Get(2),True) 'setSegment(bitext,index) fillOne(index,resultList.Get(2)) End If Else if options.Get("type")="MT" Then wait for (MT.getMT(bitext.Get(0),projectFile.Get("source"),projectFile.Get("target"),options.Get("engine"))) Complete (translation As String) If translation<>"" Then - setTranslation(index,translation) + setTranslation(index,translation,False) 'setSegment(bitext,index) fillOne(index,translation) End If @@ -1860,14 +1851,31 @@ Sub fillOne(index As Int,translation As String) Try Dim p As Pane p=Main.editorLV.Items.Get(index) + Dim targetTextArea As TextArea + targetTextArea=p.GetNode(1) + targetTextArea.Text=translation + Dim bitext As List + bitext=segments.Get(index) + Dim extra As Map + extra=bitext.Get(4) + setPaneStatus(extra,p) + contentIsChanged Catch Log(LastException) - Return End Try - Dim targetTextArea As TextArea - targetTextArea=p.GetNode(1) - targetTextArea.Text=translation - contentIsChanged +End Sub + +Sub setPaneStatus(extra As Map,segmentPane As Pane) + If extra.ContainsKey("neglected") Then + If extra.Get("neglected")="yes" Then + Utils.disableTextArea(segmentPane) + End If + End If + If extra.ContainsKey("note") Then + If extra.Get("note")<>"" Then + CSSUtils.SetStyleProperty(segmentPane.GetNode(1),"-fx-background-color","green") + End If + End If End Sub Public Sub fillVisibleTargetTextArea @@ -1893,7 +1901,7 @@ End Sub 'impl '-------------------------- -Public Sub setTranslation(index As String,translation As String) +Public Sub setTranslation(index As String,translation As String,isFromTM As Boolean) If segments.Size=0 Then Return End If @@ -1901,19 +1909,46 @@ Public Sub setTranslation(index As String,translation As String) bitext=segments.Get(index) If translation<>bitext.Get(1) Then bitext.Set(1,translation) - Dim time As String=DateTime.Now + Dim time As Long + time=DateTime.Now Dim extra As Map extra=bitext.Get(4) - extra.Put("createdTime",time) + Dim creator As String If settings.GetDefault("sharingTM_enabled",False)=True Then - extra.Put("creator",Main.preferencesMap.GetDefault("vcs_username","anonymous")) + creator=Main.preferencesMap.GetDefault("vcs_username","anonymous") Else If settings.GetDefault("git_enabled",False)=False Then - extra.Put("creator",Main.preferencesMap.GetDefault("vcs_username","")) + creator=Main.preferencesMap.GetDefault("vcs_username","") Else - extra.Put("creator",Main.preferencesMap.GetDefault("vcs_username","anonymous")) + creator=Main.preferencesMap.GetDefault("vcs_username","anonymous") End If End If + If isFromTM Then + Dim targetMap As Map + targetMap.Initialize + Dim source As String + source=bitext.Get(0) + If projectTM.translationMemory.ContainsKey(source) Then + targetMap=projectTM.translationMemory.Get(source) + Else if projectTM.externalTranslationMemory.ContainsKey(source) Then + targetMap=projectTM.externalTranslationMemory.Get(source) + End If + If targetMap.ContainsKey("createdTime") Then + Try + time=targetMap.Get("createdTime") + Catch + Log(LastException) + End Try + End If + If targetMap.ContainsKey("creator") Then + creator=targetMap.Get("creator") + End If + If targetMap.ContainsKey("note") Then + extra.Put("note",targetMap.Get("note")) + End If + End If + extra.Put("createdTime",time) + extra.Put("creator",creator) End If End Sub @@ -1925,7 +1960,12 @@ Sub saveOneTranslationToTM(bitext As List,index As Int) Dim creator As String Dim extra As Map extra=bitext.Get(4) - createdTime=extra.GetDefault("createdTime",0) + Try + createdTime=extra.GetDefault("createdTime",0) + Catch + Log(LastException) + End Try + creator=extra.GetDefault("creator","anonymous") Dim targetMap As Map @@ -1963,7 +2003,7 @@ Public Sub saveAlltheTranslationToSegmentsInVisibleArea(FirstIndex As Int, LastI End Try targetTextArea=p.GetNode(1) - setTranslation(i,targetTextArea.Text) + setTranslation(i,targetTextArea.Text,False) 'projectTM.addPair(bitext.Get(0),bitext.Get(1)) Next @@ -1974,7 +2014,7 @@ Sub saveTranslation(targetTextArea As TextArea) index=Main.editorLV.Items.IndexOf(targetTextArea.Parent) Dim bitext As List bitext=segments.Get(index) - setTranslation(index,targetTextArea.Text) + setTranslation(index,targetTextArea.Text,False) If targetTextArea.Text<>"" Then saveOneTranslationToTM(bitext,index) End If diff --git a/BasicCAT/TM.bas b/BasicCAT/TM.bas index 8045360..3684e71 100644 --- a/BasicCAT/TM.bas +++ b/BasicCAT/TM.bas @@ -151,6 +151,8 @@ End Sub Sub addPair(source As String,targetMap As Map) Dim target As String target=targetMap.Get("text") + Dim note As String + note=targetMap.Get("note") Dim createdTime As Long createdTime=targetMap.Get("createdTime") If translationMemory.ContainsKey(source) Then @@ -158,7 +160,9 @@ Sub addPair(source As String,targetMap As Map) previousTargetMap=translationMemory.Get(source) Dim previousCreatedTime As Long=previousTargetMap.GetDefault("createdTime",0) If previousTargetMap.Get("text")=target Then - Return + If previousTargetMap.GetDefault("note","")=note Then + Return + End If End If If previousCreatedTime>createdTime Then Return @@ -207,10 +211,14 @@ Public Sub importExternalTranslationMemory(tmList As List,projectFile As Map) As Dim source,target,filename As String Dim targetMap As Map targetMap.Initialize - If bitext.Size=3 Then + + If bitext.Size>=3 Then source=bitext.get(0) target=bitext.Get(1) filename=bitext.Get(2) + If bitext.Size=4 Then + targetMap=bitext.Get(3) + End If Else Continue End If diff --git a/BasicCAT/TMManager.bas b/BasicCAT/TMManager.bas index 5ae5e8b..5dcfc4f 100644 --- a/BasicCAT/TMManager.bas +++ b/BasicCAT/TMManager.bas @@ -152,7 +152,9 @@ Sub exportToFile Dim target As String target=targetMap.Get("text") bitext.Add(target) + bitext.Add(targetMap) segments.Add(bitext) + Next Dim result As Int result=fx.Msgbox2(frm,"Include tags?","","Yes","Cancel","No",fx.MSGBOX_CONFIRMATION) diff --git a/BasicCAT/TMX.bas b/BasicCAT/TMX.bas index 22bc755..f8a08f5 100644 --- a/BasicCAT/TMX.bas +++ b/BasicCAT/TMX.bas @@ -28,6 +28,8 @@ Sub importedList(dir As String,filename As String,sourceLang As String,targetLan bitext.Initialize Dim tuvList As List tuvList=XMLUtils.GetElements(tu,"tuv") + Dim targetMap As Map + targetMap.Initialize bitext.Add("source") bitext.Add("target") For Each tuv As Map In tuvList @@ -44,9 +46,39 @@ Sub importedList(dir As String,filename As String,sourceLang As String,targetLan bitext.Set(0,tuv.Get("seg")) else if lang.StartsWith(targetLang) Then bitext.Set(1,tuv.Get("seg")) + targetMap.Put("text",tuv.Get("seg")) End If Next + If tu.ContainsKey("note") Then + targetMap.Put("note",tu.Get("note")) + End If + 'Log(tu) + If tu.ContainsKey("Attributes") Then + Dim attributes As Map + attributes=tu.Get("Attributes") + If attributes.ContainsKey("creationid") And attributes.ContainsKey("creationdate") Then + Try + Dim creationdate As String + creationdate=attributes.Get("creationdate") + DateTime.DateFormat="yyyyMMdd" + DateTime.TimeFormat="HHmmss" + Dim date As String + Dim time As String + date=creationdate.SubString2(0,creationdate.IndexOf("T")) + time=creationdate.SubString2(creationdate.IndexOf("T")+1,creationdate.IndexOf("Z")) + 'Log("date: "&date) + 'Log("time: "&time) + 'Log(DateTime.DateTimeParse(date,time)) + targetMap.Put("createdTime",DateTime.DateTimeParse(date,time)) + targetMap.Put("creator",attributes.Get("creationid")) + Catch + Log(LastException) + End Try + End If + End If + bitext.Add(filename) + bitext.Add(targetMap) segments.Add(bitext) Next Return segments @@ -72,24 +104,50 @@ Sub export(segments As List,sourceLang As String,targetLang As String,path As St Dim tuList As List tuList.Initialize For Each bitext As List In segments - Dim tuvMap As Map - tuvMap.Initialize + Dim tuMap As Map + tuMap.Initialize Dim tuvList As List tuvList.Initialize + Dim index As Int=0 For Each seg As String In bitext If includeTag=False Then seg=Regex.Replace2("<.*?>",32,seg,"") End If index=index+1 - If index Mod 2=0 Then + If index = 2 Then tuvList.Add(CreateMap("Attributes":CreateMap("xml:lang":targetLang),"seg":seg)) - Else + Else if index = 1 Then tuvList.Add(CreateMap("Attributes":CreateMap("xml:lang":sourceLang),"seg":seg)) End If Next - tuvMap.Put("tuv",tuvList) - tuList.Add(tuvMap) + + Dim targetMap As Map + targetMap=bitext.Get(2) + + If targetMap.ContainsKey("note") Then + tuMap.Put("note",targetMap.Get("note")) + End If + + Dim attributes As Map + attributes.Initialize + If targetMap.ContainsKey("creator") Then + attributes.Put("creationid",targetMap.Get("creator")) + End If + If targetMap.ContainsKey("createdTime") Then + Dim creationDate As String + DateTime.DateFormat="yyyyMMdd" + DateTime.TimeFormat="HHmmss" + creationDate=DateTime.Date(targetMap.Get("createdTime"))&"T"&DateTime.Time(targetMap.Get("createdTime"))&"Z" + attributes.Put("creationdate",creationDate) + End If + + If attributes.Size<>0 Then + tuMap.Put("Attributes",attributes) + End If + + tuMap.Put("tuv",tuvList) + tuList.Add(tuMap) Next body.Put("tu",tuList) tmxMap.Put("body",body) diff --git a/BasicCAT/confirmReviewDialog.bas b/BasicCAT/confirmReviewDialog.bas index 7d30ad5..b404fa8 100644 --- a/BasicCAT/confirmReviewDialog.bas +++ b/BasicCAT/confirmReviewDialog.bas @@ -93,7 +93,7 @@ Sub confirmButton_MouseClicked (EventData As MouseEvent) target=target.SubString2(0,target.IndexOf("--------note:")) target=target.Trim End If - thisProject.setTranslation(index,target) + thisProject.setTranslation(index,target,False) thisProject.fillOne(index,target) loadNextOne End Sub @@ -111,7 +111,7 @@ Sub confirmAllButton_MouseClicked (EventData As MouseEvent) target=target.SubString2(0,target.IndexOf("--------note:")) target=target.Trim End If - thisProject.setTranslation(index,target) + thisProject.setTranslation(index,target,False) thisProject.fillOne(index,target) End If index=index+1 diff --git a/BasicCAT/searchAndReplaceDialog.bas b/BasicCAT/searchAndReplaceDialog.bas index c876e73..0c2ceb0 100644 --- a/BasicCAT/searchAndReplaceDialog.bas +++ b/BasicCAT/searchAndReplaceDialog.bas @@ -310,7 +310,7 @@ Sub replaceSelectedButton_MouseClicked (EventData As MouseEvent) bitext=Main.currentProject.segments.Get(tagList.Get(0)) If bitext.Get(1)=target Then 'bitext.Set(1,after) - Main.currentProject.setTranslation(tagList.Get(0),after) + Main.currentProject.setTranslation(tagList.Get(0),after,False) End If 'Main.currentProject.setSegment(tagList.Get(0),bitext) Main.currentProject.fillVisibleTargetTextArea @@ -339,7 +339,7 @@ Sub replaceAllButton_MouseClicked (EventData As MouseEvent) bitext=Main.currentProject.segments.Get(tagList.Get(0)) If bitext.Get(1)=target Then 'bitext.Set(1,after) - Main.currentProject.setTranslation(tagList.Get(0),after) + Main.currentProject.setTranslation(tagList.Get(0),after,False) End If 'Main.currentProject.setSegment(tagList.Get(0),bitext) Main.currentProject.fillVisibleTargetTextArea