forked from tannerhelland/VBIDEUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtractString.bas
634 lines (515 loc) · 20.2 KB
/
ExtractString.bas
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
Attribute VB_Name = "ExtractString_Module"
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 13/10/99
' * Time : 16:19
' * Module Name : ExtractString_Module
' * Module Filename : ExtractString.bas
' **********************************************************************
' * Comments :
' *
' *
' **********************************************************************
Option Explicit
Public colExceptLine As Collection
Public colExceptAssign As Collection
Public colExceptString As Collection
Public gbExceptLine As Boolean
Public gbExceptAssign As Boolean
Public gbExceptString As Boolean
Public gbExceptAllUpperCase As Boolean
Public gbGetMinimumSize As Boolean
Public gnGetMinimumSize As Integer
Public colExtracted As Collection
Public colRefused As Collection
Public Sub ExtractString()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 30/10/98
' * Time : 14:47
' * Module Name : ExtractString_Module
' * Module Filename : ExtractString.bas
' * Procedure Name : ExtractString
' * Parameters :
' **********************************************************************
' * Comments : Extract all strings from a project
' *
' *
' **********************************************************************
' #VBIDEUtilsERROR#
On Error GoTo ERROR_ExtractString
Dim sBuffer As String
Dim nI As Long
Dim nJ As Long
Dim nK As Long
Dim nPos As Long
Dim nPos1 As Long
Dim nPreviousPos As Long
Dim nSelLen As Long
Dim nStart As Long
Dim nNextStart As Long
Dim nComponent As Integer
Dim sLine As String
Dim sTmp As String
Dim bExceptString As Boolean
Dim cmp As VBComponent
Dim nFile As Integer
Dim nPosChar As Integer
Dim nLines As Long
Dim cHourglass As class_Hourglass
Set cHourglass = New class_Hourglass
Set frmProgress = Nothing
Set colExtracted = Nothing
Set colRefused = Nothing
' *** If we couldn't get it, quit
If VBInstance.ActiveVBProject Is Nothing Then
'Call MsgBoxTop(Me.hwnd, "Could not identify current project", vbExclamation + vbOKOnly + vbDefaultButton1, "Indentify the project")
Exit Sub
End If
Set colExtracted = New Collection
Set colRefused = New Collection
frmProgress.MessageText = "Extracting strings from the project"
Load frmProgress
frmProgress.Show
frmProgress.ZOrder
DoEvents
frmProgress.Maximum = VBInstance.ActiveVBProject.VBComponents.Count
nComponent = 1
' *** Get all components in the project
For Each cmp In VBInstance.ActiveVBProject.VBComponents
frmProgress.Progress = nComponent
' *** Get the code of the component
On Error Resume Next
nFile = FreeFile
Open cmp.FileNames(1) For Binary Access Read As #nFile
sBuffer = Input(LOF(nFile), nFile)
Close #nFile
On Error GoTo ERROR_ExtractString
nNextStart = 1
nLines = CountLine(sBuffer)
For nI = 1 To nLines
sLine = GetNextLine(sBuffer, nNextStart)
sLine = Trim$(sLine)
nPos = InStr(sLine, Chr$(34))
If nPos > 0 Then
' *** Inside a string
nPreviousPos = 1
bExceptString = False
Get_String:
' *** Check if we need to except all the line
' *** Check if we are in a comment
nPos1 = InStr(sLine, "'")
If (nPos1 > 0) And (nPos1 < nPos) Then GoTo Next_Line
' *** Check if we need to except the line
If gbExceptLine Then
For nK = 1 To colExceptLine.Count
If InStr(sLine, colExceptLine(nK)) > 0 Then GoTo Next_Line
Next
End If
' *** Check if we need to except the string due to something before
If gbExceptAssign Then
For nK = 1 To colExceptAssign.Count
nPos1 = InStr(sLine, colExceptAssign(nK))
If (nPos1 > 0) And (nPos1 < nPos) Then
bExceptString = True
nPreviousPos = nPos
Exit For
End If
Next
End If
' *** We can continue
nSelLen = 1
nStart = nPos + 1
For nJ = nStart To Len(sLine)
If (Mid$(sLine, nJ, 1) = Chr(34)) Then
If Mid$(sLine, nJ + 1, 1) = Chr(34) Then
nSelLen = nSelLen + 1
Else
nSelLen = nSelLen - 1
Exit For
End If
Else
nSelLen = nSelLen + 1
End If
Next
On Error Resume Next
sTmp = Mid$(sLine, nStart, nSelLen)
If (sTmp <> "") Then
' *** Check for string containing exceptions
If gbExceptString Then
If bExceptString = False Then
For nK = 1 To colExceptString.Count
nPos1 = InStr(UCase$(sTmp), colExceptString(nK))
If (nPos1 > 0) Then
bExceptString = True
Exit For
End If
Next
End If
End If
' *** Check if all char are in uppercase
If (bExceptString = False) And (gbExceptAllUpperCase) Then
bExceptString = (UCase$(sTmp) = sTmp)
End If
' *** Check the minimum size
If gbGetMinimumSize And (Len(sTmp) < gnGetMinimumSize) Then bExceptString = True
If (bExceptString = False) Then
nPosChar = InStr(sTmp, "µ")
If nPosChar > 0 Then sTmp = left$(sTmp, nPosChar - 1)
colExtracted.Add sTmp, sTmp
Else
colRefused.Add sTmp, sTmp
End If
End If
err = 0
' *** Continue the line for possible second string
If nJ < Len(sLine) Then
bExceptString = False
nPos = InStr(nJ + 1, sLine, Chr$(34))
If nPos > 0 Then GoTo Get_String
End If
On Error GoTo ERROR_ExtractString
End If
Next_Line:
Next
nComponent = nComponent + 1
Next
frmProgress.Progress = VBInstance.ActiveVBProject.VBComponents.Count
EXIT_ExtractString:
Unload frmProgress
Exit Sub
' #VBIDEUtilsERROR#
ERROR_ExtractString:
' Select Case MsgBoxTop(Me.hwnd, "Error " & Err.number & ": " & Err.Description & vbCrLf & "in ExtractString", vbAbortRetryIgnore + vbCritical, "Error")
' Case vbAbort
' Screen.MousePointer = vbDefault
' Resume EXIT_ExtractString
' Case vbRetry
' Resume
' Case vbIgnore
' Resume Next
' End Select
Resume EXIT_ExtractString
End Sub
Public Sub InitExtractString()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 14/10/99
' * Time : 11:53
' * Module Name : ExtractString_Module
' * Module Filename : ExtractString.bas
' * Procedure Name : InitExtractString
' * Parameters :
' **********************************************************************
' * Comments : Initialise the string extraction
' *
' *
' **********************************************************************
' #VBIDEUtilsERROR#
On Error GoTo ERROR_InitExtractString
Dim sLine As String
Dim nFile As Integer
Dim sBuffer As String
Dim nI As Long
' *** Get all the line exception
Set colExceptLine = Nothing
Set colExceptLine = New Collection
On Error Resume Next
nFile = FreeFile
Open App.Path & "\Extract1.txt" For Binary Access Read As #nFile
sBuffer = Input(LOF(nFile), nFile)
Close #nFile
On Error GoTo ERROR_InitExtractString
For nI = 1 To CountLine(sBuffer)
sLine = GetLine(sBuffer, nI)
On Error Resume Next
If Trim$(sLine) <> "" Then colExceptLine.Add sLine, sLine
On Error GoTo ERROR_InitExtractString
Next
' *** Get all the assignment string exception
Set colExceptAssign = Nothing
Set colExceptAssign = New Collection
On Error Resume Next
nFile = FreeFile
Open App.Path & "\Extract2.txt" For Binary Access Read As #nFile
sBuffer = Input(LOF(nFile), nFile)
Close #nFile
For nI = 1 To CountLine(sBuffer)
sLine = GetLine(sBuffer, nI)
On Error Resume Next
If Trim$(sLine) <> "" Then colExceptAssign.Add sLine, sLine
On Error GoTo ERROR_InitExtractString
Next
' *** Get all the string exception
Set colExceptString = Nothing
Set colExceptString = New Collection
On Error Resume Next
nFile = FreeFile
Open App.Path & "\Extract3.txt" For Binary Access Read As #nFile
sBuffer = Input(LOF(nFile), nFile)
Close #nFile
For nI = 1 To CountLine(sBuffer)
sLine = GetLine(sBuffer, nI)
On Error Resume Next
If Trim$(sLine) <> "" Then colExceptString.Add sLine, sLine
On Error GoTo ERROR_InitExtractString
Next
gbExceptLine = (GetSetting(gsREG_APP, "ExtractString", "ExceptLine", "Y") = "Y")
gbExceptAssign = (GetSetting(gsREG_APP, "ExtractString", "ExceptAssign", "Y") = "Y")
gbExceptString = (GetSetting(gsREG_APP, "ExtractString", "ExceptString", "Y") = "Y")
gbExceptAllUpperCase = (GetSetting(gsREG_APP, "ExtractString", "ExceptAllUpperCase", "Y") = "Y")
gbGetMinimumSize = (GetSetting(gsREG_APP, "ExtractString", "IsGetMinimumSize", "Y") = "Y")
gnGetMinimumSize = GetSetting(gsREG_APP, "ExtractString", "NumGetMinimumSize", "2")
EXIT_InitExtractString:
DoEvents
Exit Sub
' #VBIDEUtilsERROR#
ERROR_InitExtractString:
' Select Case MsgBoxTop(Me.hwnd, "Error " & Err.number & ": " & Err.Description & vbCrLf & "in InitExtractString", vbAbortRetryIgnore + vbCritical, "Error")
' Case vbAbort
' Screen.MousePointer = vbDefault
' Resume EXIT_InitExtractString
' Case vbRetry
' Resume
' Case vbIgnore
' Resume Next
' End Select
Resume EXIT_InitExtractString
End Sub
Public Sub InternationalizeProject(sDB As String)
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 30/10/98
' * Time : 14:47
' * Module Name : InternationalizeProject_Module
' * Module Filename : InternationalizeProject.bas
' * Procedure Name : InternationalizeProject
' * Parameters :
' **********************************************************************
' * Comments : Internationalize all the project
' *
' *
' **********************************************************************
' #VBIDEUtilsERROR#
On Error GoTo ERROR_InternationalizeProject
Dim sBuffer As String
Dim nI As Long
Dim nJ As Long
Dim nK As Long
Dim nPos As Long
Dim nPos1 As Long
Dim nPreviousPos As Long
Dim nSelLen As Long
Dim nStart As Long
Dim nNextStart As Long
Dim nComponent As Integer
Dim sLine As String
Dim sTmp As String
Dim sTmp2 As String
Dim bExceptString As Boolean
Dim cmp As VBComponent
Dim nFile As Integer
Dim bHeader As Boolean
Dim DBTranslate As Database
Dim sSQL As String
Dim record As Recordset
Dim sNewFile As String
Dim sNewLine As String
Dim sName As String
Dim nPosChar As Integer
Dim cHourglass As class_Hourglass
Set cHourglass = New class_Hourglass
Set frmProgress = Nothing
Set colExtracted = Nothing
' *** If we couldn't get it, quit
If VBInstance.ActiveVBProject Is Nothing Then
'Call MsgBoxTop(Me.hwnd, "Could not identify current project", vbExclamation + vbOKOnly + vbDefaultButton1, "Indentify the project")
Exit Sub
End If
Set DBTranslate = DAO.OpenDatabase(sDB)
frmProgress.MessageText = "Internationalizing the current project"
Load frmProgress
frmProgress.Show
frmProgress.ZOrder
DoEvents
frmExtractString.lstResult.AddItem "Internationalizing " & VBInstance.ActiveVBProject.Name
frmExtractString.lstResult.AddItem ""
frmExtractString.lstResult.AddItem VBInstance.ActiveVBProject.VBComponents.Count & " components to internationalize"
frmExtractString.lstResult.AddItem ""
frmProgress.Maximum = VBInstance.ActiveVBProject.VBComponents.Count
nComponent = 1
' *** Get all components in the project
For Each cmp In VBInstance.ActiveVBProject.VBComponents
sName = cmp.Name
frmExtractString.lstResult.AddItem "Working on " & sName
frmProgress.Progress = nComponent
' *** Get the code of the component
On Error Resume Next
nFile = FreeFile
Open cmp.FileNames(1) For Binary Access Read As #nFile
sBuffer = Input(LOF(nFile), nFile)
Close #nFile
On Error GoTo ERROR_InternationalizeProject
bHeader = True
sNewFile = ""
nNextStart = 1
For nI = 1 To CountLine(sBuffer)
sLine = GetNextLine(sBuffer, nNextStart)
sNewLine = sLine
nPos = InStr(sLine, Chr$(34))
If nPos > 0 Then
' *** Check if we are in the file header
If InStr(sLine, "Attribute VB_Name = ") > 0 Then bHeader = False
' *** Inside a string
nPreviousPos = 1
bExceptString = False
Get_String:
' *** Check if we need to except all the line
' *** Check if we are in a comment
nPos1 = InStr(sLine, "'")
If (nPos1 > 0) And (nPos1 < nPos) Then GoTo Next_Line
' *** Check if we need to except the line
If gbExceptLine Then
For nK = 1 To colExceptLine.Count
If InStr(sLine, colExceptLine(nK)) > 0 Then GoTo Next_Line
Next
End If
' *** Check if we need to except the string due to something before
If gbExceptAssign Then
For nK = 1 To colExceptAssign.Count
nPos1 = InStr(sLine, colExceptAssign(nK))
If (nPos1 > 0) And (nPos1 < nPos) Then
bExceptString = True
nPreviousPos = nPos
Exit For
End If
Next
End If
' *** We can continue
nSelLen = 1
nStart = nPos + 1
For nJ = nStart To Len(sLine)
If (Mid$(sLine, nJ, 1) = Chr(34)) Then
If Mid$(sLine, nJ + 1, 1) = Chr(34) Then
nSelLen = nSelLen + 1
Else
nSelLen = nSelLen - 1
Exit For
End If
Else
nSelLen = nSelLen + 1
End If
Next
On Error Resume Next
sTmp = Mid$(sLine, nStart, nSelLen)
If (sTmp <> "") Then
' *** Check for string containing exceptions
If gbExceptString Then
If bExceptString = False Then
For nK = 1 To colExceptString.Count
nPos1 = InStr(UCase$(sTmp), colExceptString(nK))
If (nPos1 > 0) Then
bExceptString = True
Exit For
End If
Next
End If
End If
' *** Check if all char are in uppercase
If (bExceptString = False) And (gbExceptAllUpperCase) Then
bExceptString = (UCase$(sTmp) = sTmp)
End If
' *** Check the minimum size
If gbGetMinimumSize And (Len(sTmp) < gnGetMinimumSize) Then bExceptString = True
If (bExceptString = False) Then
' *** Internationalize this string
' *** Verify if already internaionalized
sTmp2 = sTmp
nPosChar = InStr(sTmp, "µ")
If nPosChar > 0 Then sTmp = left$(sTmp, nPosChar - 1)
sSQL = "Select * From Translation "
sSQL = sSQL & "Where Original = '" & Replace(sTmp, "'", "''") & "' "
Set record = DBTranslate.OpenRecordset(sSQL, DAO.dbOpenDynaset)
If record.RecordCount > 0 Then
If nPosChar = 0 Then
' *** Not yet translated
If bHeader Then
sNewLine = Replace(sNewLine, """" & sTmp & """", """" & record("Original") & "µ" & record("ID") & """")
Else
sNewLine = Replace(sNewLine, """" & sTmp & """", "Translation(""" & record("Original") & "µ" & record("ID") & """)")
End If
Else
' *** Already translated
sNewLine = Replace(sNewLine, """" & sTmp & """", """" & record("Original") & "µ" & record("ID") & """")
End If
End If
record.Close
Set record = Nothing
End If
End If
err = 0
' *** Continue the line for possible second string
If nJ < Len(sLine) Then
bExceptString = False
nPos = InStr(nJ + 1, sLine, Chr$(34))
If nPos > 0 Then GoTo Get_String
End If
On Error GoTo ERROR_InternationalizeProject
End If
Next_Line:
sNewFile = sNewFile & sNewLine & vbCrLf
Next
' *** Save the new file
sNewFile = Trim$(sNewFile)
If FileExist(cmp.FileNames(1)) Then
nFile = FreeFile
Open cmp.FileNames(1) For Output Access Write As #nFile
Print #nFile, sNewFile
Close #nFile
' *** Reload the components
On Error Resume Next
cmp.Reload
On Error GoTo ERROR_InternationalizeProject
frmExtractString.lstResult.AddItem sName & " done and saved"
Else
frmExtractString.lstResult.AddItem sName & " not saved"
End If
frmExtractString.lstResult.AddItem ""
nComponent = nComponent + 1
Next
frmProgress.Progress = VBInstance.ActiveVBProject.VBComponents.Count
frmExtractString.lstResult.AddItem VBInstance.ActiveVBProject.Name & " done"
frmExtractString.lstResult.AddItem ""
frmExtractString.lstResult.AddItem "Add in the Form_Load of each form the following code"
frmExtractString.lstResult.AddItem " Call InternationalizeForm(Me)"
frmExtractString.lstResult.AddItem ""
frmExtractString.lstResult.AddItem "Add also the Internationalization.bas"
frmExtractString.lstResult.AddItem " wich implements all the needed functions"
frmExtractString.lstResult.AddItem ""
EXIT_InternationalizeProject:
On Error Resume Next
DBTranslate.Close
Set DBTranslate = Nothing
Unload frmProgress
Exit Sub
' #VBIDEUtilsERROR#
ERROR_InternationalizeProject:
' Select Case MsgBoxTop(Me.hwnd, "Error " & Err.number & ": " & Err.Description & vbCrLf & "in InternationalizeProject", vbAbortRetryIgnore + vbCritical, "Error")
' Case vbAbort
' Screen.MousePointer = vbDefault
' Resume EXIT_InternationalizeProject
' Case vbRetry
' Resume
' Case vbIgnore
' Resume Next
' End Select
Resume EXIT_InternationalizeProject
End Sub