Skip to content

Commit

Permalink
add note and creation info for tmx export and import; apply extra inf…
Browse files Browse the repository at this point in the history
…o when applying a tm
  • Loading branch information
xulihang committed Mar 31, 2019
1 parent 5ef00e9 commit 79acc0e
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 90 deletions.
105 changes: 54 additions & 51 deletions BasicCAT/BasicCAT.b4j
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion BasicCAT/BasicCAT.b4j.meta
Original file line number Diff line number Diff line change
Expand Up @@ -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
92 changes: 66 additions & 26 deletions BasicCAT/Project.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -1893,27 +1901,54 @@ 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
Dim bitext As List
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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions BasicCAT/TM.bas
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,18 @@ 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
Dim previousTargetMap 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions BasicCAT/TMManager.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 79acc0e

Please sign in to comment.