'#Reference {420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINNT\System32\scrrun.dll#Microsoft Scripting Runtime
''Reports the possible translations of all bookmarked items in a protocol file in the project directory

'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
'EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
'OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE

Option Explicit

Sub Main
    Dim prj As PslProject

    ' Do we have an open project?
    Set prj = PSL.ActiveProject
    If prj Is Nothing Then
		MsgBox("No active PASSOLO project.")
		Exit Sub
	End If

    ' Create protocol file
	Dim fname As String
	fname = prj.Location & "\protokoll.txt"
    Dim fso As FileSystemObject
    Dim out As TextStream
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.FileExists(fname) Then
		If MsgBox("Overwrite existing protocol file?", vbYesNo) = vbNo Then
			Exit Sub
		End If
	End If
	Set out = fso.CreateTextFile(fname, True)

    ' Report general data
    out.WriteLine("Created:   " & Date & " " & Time)
    out.WriteLine("Project:   " & prj.Name)
    out.WriteLine("Location:  " & prj.Location)

	Dim i, j, k As Integer
	Dim MustOpen As Boolean
	Dim MustClose As Boolean
	Dim HeaderReported As Boolean
    Dim trn As PslTransList
   	Dim trans As PslTranslations
	Dim srcstr As String
    Dim trncnt As Integer
	trncnt = prj.TransLists.Count

	' Parse thru all translation list?
	MustOpen = False
	If MsgBox("Report open translation lists only?" & vbCrLf & vbCrLf & "NO will look into all translation lists in all languages." & vbCrLf & "This can take several minutes.", vbYesNo) = vbNo Then
		MustOpen = True
	End If

	' Examine all translation lists
	For i = 1 To trncnt
		HeaderReported = False
		Set trn = prj.TransLists.Item(i)

		' Look if list is open
		If Not trn.IsOpen Then
			If MustOpen Then
				trn.Open
				MustClose = True
			End If
		Else
			MustClose = False
		End If

		' Only open lists will be reported
		If trn.IsOpen Then
			' Examine all string in the current translation list
	    	For j = 1 To trn.StringCount
		       	' Bookmarked string?
	    		If trn.String(j).State(pslStateBookmark) = True Then

					' Report translation list data
					If Not HeaderReported Then
						out.WriteLine("")
						out.WriteLine("Translation list:         " & trn.SourceList.Title)
						out.WriteLine("Language:                 " & PSL.GetLangCode(trn.Language.LangID, pslCodeText))
						out.WriteLine("*********************************************************************************")
						out.WriteLine("")
						HeaderReported = True
					End If

					' Read source string from translation list
		        	srcstr = trn.String(j).SourceText

		        	' Report source string into file
	        		out.WriteLine("Number:                   " & j)
	        		out.WriteLine("Resource:                 " & trn.String(j).Type & " " & trn.String(j).ID & " in " & trn.String(j).ResType & " " & trn.String(j).Resource.ID)
	    	    	out.WriteLine("String to translate:      " & srcstr)

					' Check possible translations
					Set trans = trn.TranslateText(srcstr, 99, 100)
					If trans.Count <> 0 Then
						' Report all possible translations
						For k = 1 To trans.Count
							out.WriteLine("Possible translation:     " & trans.Item(k).TransString & " --> found in: " & trans.Item(k).Origin)
						Next
					Else
						out.WriteLine("Oops! No other translations found.")
					End If
					out.WriteLine("---------------------------------------------------------------------------------")
				End If
	    	Next j

			' Close lists we have opened
			If MustClose Then
				trn.Close
			End If
		End If
	Next i

	' Close Report and open it with Notepad
	out.Close
	Shell("notepad.exe " & fname, vbNormalFocus)
End Sub
