-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExporter.bas
More file actions
108 lines (101 loc) · 2.56 KB
/
Exporter.bas
File metadata and controls
108 lines (101 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=10
@EndOfDesignText@
'Static code module
Sub Process_Globals
Private fx As JFX
End Sub
Public Sub ExportToSRT(lines As List,path As String,askOption As Boolean,option As Int)
If askOption Then
Dim optionsForm As ExportOptions
optionsForm.Initialize
option = optionsForm.ShowAndWait
If option = -1 Then
Return
End If
End If
Dim sb As StringBuilder
sb.Initialize
Dim index As Int = 0
For Each line As Map In lines
sb.Append(index+1)
sb.Append(Chr(13))
sb.Append(Chr(10))
sb.Append(line.Get("startTime"))
sb.Append(" --> ")
sb.Append(line.Get("endTime"))
sb.Append(Chr(13))
sb.Append(Chr(10))
If option = 0 Then
If Regex.IsMatch("\d+",line.Get("source")) Then
sb.Append(" "&line.Get("source")&" ")
Else
sb.Append(line.Get("source"))
End If
else if option = 1 Then
If Regex.IsMatch("\d+",line.Get("target")) Then
sb.Append(" "&line.Get("target")&" ")
Else
sb.Append(line.Get("target"))
End If
Else
sb.Append(line.Get("source"))
sb.Append(Chr(13))
sb.Append(Chr(10))
sb.Append(line.Get("target"))
End If
sb.Append(Chr(13))
sb.Append(Chr(10))
sb.Append(Chr(13))
sb.Append(Chr(10))
index = index + 1
Next
File.WriteString(path,"",sb.ToString)
End Sub
Public Sub ExportToXLIFF(lines As List,path As String,sourceLang As String,targetLang As String)
XLIFF.Export(lines,path,sourceLang,targetLang)
End Sub
Public Sub ExportToPlainTXT(lines As List,isSource As Boolean,path As String)
Dim sb As StringBuilder
sb.Initialize
For Each line As Map In lines
If isSource Then
sb.Append(Escape(line.Get("source")))
Else
sb.Append(Escape(line.Get("target")))
End If
sb.Append(CRLF)
Next
File.WriteString(path,"",sb.ToString)
End Sub
Public Sub ExportToTXT(lines As List,path As String)
Dim sb As StringBuilder
sb.Initialize
For Each line As Map In lines
sb.Append(line.Get("startTime"))
sb.Append(" ")
sb.Append(line.Get("endTime"))
sb.Append(" ")
sb.Append(Escape(line.Get("source")))
sb.Append(" ")
sb.Append(Escape(line.Get("target")))
sb.Append(CRLF)
Next
File.WriteString(path,"",sb.ToString)
End Sub
Private Sub Escape(str As String) As String
str = str.Replace(" ","\t")
str = str.Replace(CRLF,"\n")
If str = "" Then
str = " "
End If
Return str
End Sub
public Sub Unescape(str As String) As String
str = str.Replace("\t"," ")
str = str.Replace("\n",CRLF)
Return str.Trim
End Sub