Skip to content

Commit

Permalink
fixes target replacement for xliff filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xulihang committed Apr 28, 2020
1 parent e180da0 commit 31ed8e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions BasicCAT/BasicCAT.b4j.meta
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,6 @@ ModuleClosedNodes68=
ModuleClosedNodes7=
ModuleClosedNodes8=
ModuleClosedNodes9=
NavigationStack=xliffFilter,Process_Globals,5,0,xliffFilter,updateTransUnits,493,0,xliffFilter,shouldAddSpace,571,0,xliffFilter,mergeSegment,605,0,XMLUtils,GetElements,38,0,XMLUtils,escapedText,55,6,xliffFilter,createWorkFile,19,6,xliffFilter,checkSegContinuous,354,0,xliffFilter,insertTranslation,355,0,xliffFilter,generateFile,339,0
NavigationStack=Xml2Map,Parser_StartElement,83,0,xliffFilter,getTransUnits,173,0,XMLUtils,GetElements,40,0,XMLUtils,escapedText,40,6,XMLUtils,unescapeInlineTag,141,0,xliffFilter,generateFile,339,0,XMLUtils,getXmlMap,10,0,Xml2Map,Parser_EndElement,93,0,xliffFilter,createWorkFile,18,6,xliffFilter,insertTranslation,359,1
SelectedBuild=0
VisibleModules=1,2,3,4,5,6,7,8,9,10,11,12
VisibleModules=1,2,3,4,5,6,7,8,9,10,11,12,29,41
18 changes: 11 additions & 7 deletions BasicCAT/xliffFilter.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ Sub createWorkFile(filename As String,path As String,sourceLang As String,senten
Dim files As List
Dim xmlstring As String=File.ReadString(File.Combine(path,"source"),filename)
xmlstring=XMLUtils.escapedText(xmlstring,"source","xliff")
xmlstring=XMLUtils.escapedText(xmlstring,"mrk","xliff")
xmlstring=Regex.Replace("<target\b.*?/>",xmlstring,"<target></target>")
xmlstring=XMLUtils.escapedText(xmlstring,"target","xliff")
If xmlstring.Contains("<seg-source>")=False Then
xmlstring=Regex.Replace("<target */>",xmlstring,"<target></target>")
xmlstring=XMLUtils.escapedText(xmlstring,"target","xliff")
Else
xmlstring=XMLUtils.escapedText(xmlstring,"mrk","xliff")
End If

Log("escape done")

'Log(xmlstring)

files=getFilesList(xmlstring)

Expand Down Expand Up @@ -343,7 +347,6 @@ Sub generateFile(filename As String,path As String,projectFile As Map)
xmlString=XMLUtils.getXmlFromMapWithoutIndent(insertTranslation(translationMap,filename,path,isSegEnabled))
xmlString=XMLUtils.unescapedText(xmlString,"source","xliff")
xmlString=XMLUtils.unescapedText(xmlString,"seg-source","xliff")
'xmlString=Regex.Replace("<target\b.*?/>",xmlString,"<target></target>")
xmlString=XMLUtils.unescapedText(xmlString,"target","xliff")
'Log(xmlString)
File.WriteString(File.Combine(path,"target"),filename,xmlString)
Expand All @@ -363,10 +366,11 @@ Sub insertTranslation(translationMap As Map,filename As String,path As String,is
Dim xmlstring As String
xmlstring=File.ReadString(File.Combine(path,"source"),filename)
xmlstring=XMLUtils.escapedText(xmlstring,"source","xliff")
xmlstring=XMLUtils.escapedText(xmlstring,"seg-source","xliff")
If isSegEnabled=False Then
xmlstring=Regex.Replace("<target\b.*?/>",xmlstring,"<target></target>")
xmlstring=Regex.Replace("<target */>",xmlstring,"<target></target>")
xmlstring=XMLUtils.escapedText(xmlstring,"target","xliff")
Else
xmlstring=XMLUtils.escapedText(xmlstring,"seg-source","xliff")
End If
'File.WriteString(path,"out.xml",xmlstring)
'Log("xml"&xmlstring)
Expand Down

0 comments on commit 31ed8e6

Please sign in to comment.