Option Explicit '' ' This script gets the status of the translations. ' ' Copyright (C) 2007 by Tim Gerundt ' Released under the "GNU General Public License" ' ' ID line follows -- this is updated by SVN ' $Id$ Const ForReading = 1 Const SvnWebUrlLanguages = "http://winmerge.svn.sourceforge.net/viewvc/winmerge/trunk/Translations/WinMerge/" Dim oFSO, bRunFromCmd Set oFSO = CreateObject("Scripting.FileSystemObject") bRunFromCmd = False If LCase(oFSO.GetFileName(Wscript.FullName)) = "cscript.exe" Then bRunFromCmd = True End If Call Main '' ' ... Sub Main Dim oTranslationsStatus Dim oLanguages, sLanguage Dim StartTime, EndTime, Seconds StartTime = Time InfoBox "Creating translations status files...", 3 Set oTranslationsStatus = CreateObject("Scripting.Dictionary") If (bRunFromCmd = True) Then 'If run from command line... Wscript.Echo "English" End If oTranslationsStatus.Add "English", GetTranslationsStatusFromPoFile("English.pot") Set oLanguages = GetLanguages For Each sLanguage In oLanguages.Keys 'For all languages... If (bRunFromCmd = True) Then 'If run from command line... Wscript.Echo sLanguage End If oTranslationsStatus.Add sLanguage, GetTranslationsStatusFromPoFile(oLanguages(sLanguage)) Next CreateTranslationsStatusHtmlFile "TranslationsStatus.html", oTranslationsStatus CreateTranslationsStatusWikiFile "TranslationsStatus.wiki", oTranslationsStatus CreateTranslationsStatusXmlFile "TranslationsStatus.xml", oTranslationsStatus CreateTranslatorsListFile "Translators.html", oTranslationsStatus EndTime = Time Seconds = DateDiff("s", StartTime, EndTime) InfoBox "Translations status files created, after " & Seconds & " second(s).", 10 End Sub '' ' ... Function GetLanguages() Dim oLanguages, oFile, ext, name Set oLanguages = CreateObject("Scripting.Dictionary") For Each oFile In oFSO.GetFolder(".").Files 'For all subfolders in the current folder... ext = oFSO.GetExtensionName(oFile) name = oFSO.GetBaseName(oFile) If (ext = "po") Then oLanguages.Add name, oFile.Name End If Next Set GetLanguages = oLanguages End Function '' ' ... Class CStatus Public Count, Translated, Untranslated, Fuzzy Public PoRevisionDate, PotCreationDate Public Translators Private Sub Class_Initialize Count = 0 Translated = 0 Untranslated = 0 Fuzzy = 0 PoRevisionDate = "" PotCreationDate = "" Set Translators = CreateObject("Scripting.Dictionary") End Sub Public Sub AddTranslator(ByVal sTranslator, ByVal bMaintainer) Dim Translator Set Translator = New CTranslator Translator.Maintainer = bMaintainer Translator.Mail = Trim(GetRegExpSubMatch(sTranslator, "<(.*)>")) If (Translator.Mail <> "") Then 'If mail address exists... Translator.Name = Trim(GetRegExpSubMatch(sTranslator, "(.*) <.*>")) Else 'If mail address NOT exists... Translator.Name = sTranslator End If Translators.Add Translators.Count, Translator End Sub End Class '' ' ... Class CTranslator Public Name, Mail, Maintainer End Class '' ' ... Function GetTranslationsStatusFromPoFile(ByVal sPoPath) Dim oStatus, oTextFile, sLine Dim oMatch, iMsgStarted, sMsgId, sMsgStr, bFuzzy, bMaintainer Dim reMsgId, reMsgStr, reMsgContinued Set reMsgId = New RegExp reMsgId.Pattern = "^msgid ""(.*)""$" reMsgId.IgnoreCase = True Set reMsgStr = New RegExp reMsgStr.Pattern = "^msgstr ""(.*)""$" reMsgStr.IgnoreCase = True Set reMsgContinued = New RegExp reMsgContinued.Pattern = "^""(.*)""$" reMsgContinued.IgnoreCase = True Set oStatus = New CStatus If (oFSO.FileExists(sPoPath) = True) Then 'If the PO file exists... iMsgStarted = 0 sMsgId = "" sMsgStr = "" bFuzzy = False bMaintainer = False Set oTextFile = oFSO.OpenTextFile(sPoPath, ForReading, False, -1) Do Until oTextFile.AtEndOfStream = True 'For all lines... sLine = Trim(oTextFile.ReadLine) If (sLine <> "") Then 'If NOT empty line... If (Left(sLine, 1) <> "#") Then 'If NOT comment line... If reMsgId.Test(sLine) Then 'If "msgid"... iMsgStarted = 1 Set oMatch = reMsgId.Execute(sLine)(0) sMsgId = oMatch.SubMatches(0) ElseIf reMsgStr.Test(sLine) Then 'If "msgstr"... iMsgStarted = 2 Set oMatch = reMsgStr.Execute(sLine)(0) sMsgStr = oMatch.SubMatches(0) ElseIf reMsgContinued.Test(sLine) Then 'If "msgid" or "msgstr" continued... Set oMatch = reMsgContinued.Execute(sLine)(0) If (iMsgStarted = 1) Then sMsgId = sMsgId & oMatch.SubMatches(0) ElseIf (iMsgStarted = 2) Then sMsgStr = sMsgStr & oMatch.SubMatches(0) End If End If Else 'If comment line... iMsgStarted = -1 If (Left(sLine, 2) = "#,") Then 'If "Reference" line... If (InStr(sLine, "fuzzy") > 0) Then 'If "fuzzy"... bFuzzy = True End If ElseIf (sLine = "# Maintainer:") Then 'If maintainer list starts... bMaintainer = True ElseIf (sLine = "# Translators:") Then 'If translators list starts... bMaintainer = False ElseIf (Left(sLine, 4) = "# * ") Then 'If translator/maintainer... oStatus.AddTranslator Trim(Mid(sLine, 5)), bMaintainer End If End If Else 'If empty line iMsgStarted = 0 End If If (iMsgStarted = 0) Then 'If NOT inside a translation... If (sMsgId <> "") Then oStatus.Count = oStatus.Count + 1 If (bFuzzy = False) Then 'If NOT a fuzzy translation... If (sMsgStr <> "") Then oStatus.Translated = oStatus.Translated + 1 Else oStatus.Untranslated = oStatus.Untranslated + 1 End If Else 'If a fuzzy translation... oStatus.Fuzzy = oStatus.Fuzzy + 1 End If ElseIf(sMsgStr <> "") Then oStatus.PoRevisionDate = GetRegExpSubMatch(sMsgStr, "PO-Revision-Date: ([0-9 :\+\-]+)") oStatus.PotCreationDate = GetRegExpSubMatch(sMsgStr, "POT-Creation-Date: ([0-9 :\+\-]+)") End If sMsgId = "" sMsgStr = "" bFuzzy = False End If Loop oTextFile.Close End If Set GetTranslationsStatusFromPoFile = oStatus End Function '' ' ... Sub CreateTranslationsStatusHtmlFile(ByVal sHtmlPath, ByVal oTranslationsStatus) Dim oHtmlFile, sLanguage, oLanguageStatus, i Dim sMaintainerStart, sMaintainerEnd Set oHtmlFile = oFSO.CreateTextFile(sHtmlPath, True) oHtmlFile.WriteLine "" oHtmlFile.WriteLine "" oHtmlFile.WriteLine "
" oHtmlFile.WriteLine "Status from " & GetCreationDate() & ":
" oHtmlFile.WriteLine "Language | " oHtmlFile.WriteLine "Total | " oHtmlFile.WriteLine "Translated | " oHtmlFile.WriteLine "Fuzzy | " oHtmlFile.WriteLine "Untranslated | " oHtmlFile.WriteLine "Last Update | " oHtmlFile.WriteLine "
---|---|---|---|---|---|
" & sLanguage & " | " oHtmlFile.WriteLine "" & oLanguageStatus.Count & " | " oHtmlFile.WriteLine "" & oLanguageStatus.Translated & " | " oHtmlFile.WriteLine "" & oLanguageStatus.Fuzzy & " | " oHtmlFile.WriteLine "" & oLanguageStatus.Untranslated & " | " oHtmlFile.WriteLine "" & Left(oLanguageStatus.PoRevisionDate, 10) & " | " oHtmlFile.WriteLine "
English | " oHtmlFile.WriteLine "" & oLanguageStatus.Count & " | " oHtmlFile.WriteLine "" & oLanguageStatus.Count & " | " oHtmlFile.WriteLine "0 | " oHtmlFile.WriteLine "0 | " oHtmlFile.WriteLine "" & Left(oLanguageStatus.PotCreationDate, 10) & " | " oHtmlFile.WriteLine "
Language | " oHtmlFile.WriteLine "Translator(s) | " oHtmlFile.WriteLine "
---|---|
" & sLanguage & " | " oHtmlFile.WriteLine ""
For i = 0 To oLanguageStatus.Translators.Count - 1 'For all translators...
sMaintainerStart = ""
sMaintainerEnd = ""
If (oLanguageStatus.Translators(i).Maintainer = True) Then 'If maintainer...
sMaintainerStart = ""
sMaintainerEnd = ""
End If
If (oLanguageStatus.Translators(i).Mail <> "") Then 'If mail address exists...
oHtmlFile.WriteLine " " & sMaintainerStart & "" & oLanguageStatus.Translators(i).Name & "" & sMaintainerEnd & " " Else 'If mail address NOT exists... oHtmlFile.WriteLine " " & sMaintainerStart & oLanguageStatus.Translators(i).Name & sMaintainerEnd & " " End If Next oHtmlFile.WriteLine " | "
oHtmlFile.WriteLine "
Status from " & GetCreationDate() & ". Look at winmerge.org for updates.
" oHtmlFile.WriteLine "" oHtmlFile.WriteLine "" oHtmlFile.Close End Sub '' ' ... Function FoundRegExpMatch(ByVal sString, ByVal sPattern, ByRef oMatchReturn) Dim oRegExp, oMatches Set oRegExp = New RegExp oRegExp.Pattern = sPattern oRegExp.IgnoreCase = True oMatchReturn = Null FoundRegExpMatch = False If (oRegExp.Test(sString) = True) Then Set oMatches = oRegExp.Execute(sString) Set oMatchReturn = oMatches(0) FoundRegExpMatch = True End If End Function '' ' ... Function GetRegExpSubMatch(ByVal sString, ByVal sPattern) Dim oMatch GetRegExpSubMatch = "" If (FoundRegExpMatch(sString, sPattern, oMatch)) Then 'If pattern found... GetRegExpSubMatch = oMatch.SubMatches(0) End If End Function '' ' ... Function GetCreationDate() Dim oNow, sYear, sMonth, sDay, sHour, sMinute oNow = Now() sYear = Year(oNow) sMonth = Month(oNow) If (sMonth < 10) Then sMonth = "0" & sMonth sDay = Day(oNow) If (sDay < 10) Then sDay = "0" & sDay GetCreationDate = sYear & "-" & sMonth & "-" & sDay End Function '' ' ... Function InfoBox(ByVal sText, ByVal iSecondsToWait) Dim oShell If (bRunFromCmd = False) Then 'If run from command line... Set oShell = Wscript.CreateObject("WScript.Shell") InfoBox = oShell.Popup(sText, iSecondsToWait, Wscript.ScriptName, 64) Else 'If NOT run from command line... Wscript.Echo sText End If End Function