' Gambas module file Private $cVar As New Collection Private $cTrans As New Collection Private $sLang As String Private $aLanguages As String[] = ["en:C", "fr:fr_FR.UTF-8", "es:es_ES.UTF-8", "ca:ca_ES.UTF-8", "cs:cs_CZ.UTF-8", "ar:ar_EG.UTF-8", "tr:tr_TR.UTF-8", "zh:zh_CN.UTF-8", "ko:ko_KR.UTF-8", "de:de_DE.UTF-8"] Private Const NBR_NEWS As Integer = 3 Sub InitVar() 'Dim aStable As String[] = ["2.23.1", "2.22.0", "2.21.0", "2.20.2"] 'DIM aDev AS String[] = ["92", "91", "90", "51"] $cVar["OLD_VERSION"] = "2.24.0" $cVar["DEV_VERSION"] = "3.5.1" InitAuthor End Private Sub InitAuthor() Dim hFile As File Dim hAuthor As CAuthor Dim sDev As String Dim sTrans As String Dim bDark As Boolean Dim aCountry As New String[] Dim cCountry As New Collection Dim sCountry As String Dim aAuthor As Object[] Dim iInd As Integer hFile = Open "authors.txt" For Read While Not Eof(hFile) hAuthor = New CAuthor(hFile) Wend Close #hFile CAuthor.All.Sort For Each hAuthor In CAuthor.All If hAuthor.Translator Then For Each sCountry In hAuthor.Translation If Not cCountry.Exist(sCountry) Then cCountry[sCountry] = New Object[] aCountry.Add(sCountry) Endif cCountry[sCountry].Add(hAuthor) Next Endif If hAuthor.Developer Then If bDark Then sDev &= "" Else sDev &= "" Endif bDark = Not bDark sDev &= " " & hAuthor.GetLink() & "\n" & " " & hAuthor.Country & "" & " " If hAuthor.Works.Count > 1 Then sDev &= "\n
  • " & hAuthor.Works.Join(".\n
  • ") & ".\n" Else sDev &= hAuthor.Works[0] & "." Endif sDev &= " \n" Endif Next $cVar["DEVELOPERS"] = sDev bDark = False aCountry.Sort For Each sCountry In aCountry If bDark Then sTrans &= "" Else sTrans &= "" Endif bDark = Not bDark sTrans &= " " & sCountry & "\n" sTrans &= " \n" aAuthor = cCountry[sCountry] sTrans &= " " & aAuthor[0].GetLink() & "\n" For iInd = 1 To aAuthor.Max sTrans &= "
    " & aAuthor[iInd].GetLink() & "\n" Next sTrans &= " \n\n" Next $cVar["TRANSLATORS"] = sTrans End Sub GetNews(sPath As String) As String Dim sNews As String Dim sData As String Dim iPos As Integer Dim aDate As String[] Dim dDate As Date sNews = File.Load("news.html") sData = File.Load(sPath) aDate = Split(File.BaseName(sPath), "-") dDate = Date(aDate[0], aDate[1], Left(aDate[2], 2)) If File.BaseName(sPath) = "2010-01-04" Then sNews = Replace(sNews, "$(CLASS)", "news snow") Else sNews = Replace(sNews, "$(CLASS)", "news") Endif sNews = Replace(sNews, "$(DATE)", Format(dDate, "dd mmm yyyy")) iPos = InStr(sData, "\n") sNews = Replace(sNews, "$(TITLE)", Left(sData, iPos - 1)) sNews = Replace(sNews, "$(NEWS)", Trim(Mid$(sData, iPos + 1))) Return sNews End Sub Expand(sPath As String) Dim sData As String Dim sVar As String Dim iNews As Integer Dim sKey As String Dim sFile As String Dim sSubst As String Dim sDest As String sDest = File.SetExt(sPath, "") sData = File.Load(sPath) For Each sVar In $cVar sData = Replace(sData, "$(" & $cVar.Key & ")", sVar) Next If InStr(sData, "$(HEAD_NEWS)") Then iNews = NBR_NEWS sKey = "$(HEAD_NEWS)" Else If InStr(sData, "$(NEWS)") Then iNews = 1024 sKey = "$(NEWS)" Endif If iNews Then For Each sFile In Dir("news", "*.html").Sort(gb.Descent) If $sLang And If Exist("news" &/ $sLang &/ sFile) sSubst &= GetNews("news" &/ $sLang &/ sFile) Else sSubst &= GetNews("news" &/ sFile) Endif Dec iNews If iNews <= 0 Then Break Next sData = Replace(sData, sKey, sSubst) Endif Try Kill sDest & "~" Try Move sDest To sDest & "~" File.Save(sDest, sData) CAuthor.All.Clear End Sub ReplaceMail(sPath As String) Dim sData As String = File.Load(sPath) Dim iPos, iPos2 As Integer Dim sMail As String Dim sOrig As String Dim bMail As Boolean Do iPos = InStr(sData, "href=\"mailto:", iPos + 1) If iPos = 0 Then Break iPos2 = InStr(sData, Chr$(34), iPos + 7) If iPos2 = 0 Then Break sMail = Mid$(sData, iPos, iPos2 - iPos + 1) sOrig = sMail sMail = Replace(sMail, "@", "_AT_") sMail = Replace(sMail, ".", "_DOT_") sData = Left(sData, iPos - 1) & sMail & Mid$(sData, iPos2 + 1) iPos += Len(sMail) If sOrig <> sMail Then If Not bMail Then bMail = True Print sPath Endif Endif Loop Try Kill sPath & "~" Try Move sPath To sPath & "~" File.Save(sPath, sData) End Private Sub ReplaceLink(sData As String, sAttr As String) As String Dim iPos, iPos2 As Integer Dim sLink As String Do iPos = InStr(sData, sAttr & "=\"", iPos + 1) If iPos = 0 Then Break iPos2 = InStr(sData, "\"", iPos + Len(sAttr) + 2) If iPos2 = 0 Then Break sLink = Mid$(sData, iPos + Len(sAttr) + 2, iPos2 - iPos - Len(sAttr) - 2) If Not sLink Then Continue If sLink Like "http://*" Then Continue If sLink Like "https://*" Then Continue If sLink Like "mailto:*" Then Continue If sLink Like "/" Then Continue If sLink Like "*.html" Then Continue If sLink Like "*.html#*" Then Continue If Left(sLink) = "#" Then Continue sData = Left$(sData, iPos + Len(sAttr) + 1) & ".." &/ sLink & Mid$(sData, iPos2) iPos = iPos2 Loop Return sData End Private Sub Translate(sSrc As String, sDest As String, Optional bNoTrans As Boolean) Dim sData As String = File.Load(sSrc) Dim iPos, iPos2 As Integer Dim sStr As String If InStr(sDest, "changelog3") Then Stop Print sDest If Not bNoTrans Then Do iPos = InStr(sData, "{", iPos + 1) If iPos = 0 Then Break iPos2 = InStr(sData, "}", iPos + 1) If iPos2 = 0 Then Break sStr = Mid$(sData, iPos + 1, iPos2 - iPos - 1) If InStr(sStr, "\n") Then Continue $cTrans[sStr] = sStr Print "{"; sStr; "}"; sStr = MTranslation[sStr] Print " -> "; sStr sData = Left$(sData, iPos - 1) & sStr & Mid$(sData, iPos2 + 1) Loop Endif sData = ReplaceLink(sData, "href") sData = ReplaceLink(sData, "src") sData = Replace(sData, "$(LANG)", $sLang) If $sLang = "ar" Then sData = Replace(sData, "$(LANGDIR)", "rtl") sData = Replace(sData, "$(DIR)", "-rtl") sData = Replace(sData, "$(STYLE)", "style-rtl.css") sData = Replace(sData, "$(RIGHT)", "left") Else sData = Replace(sData, "$(LANGDIR)", "ltr") sData = Replace(sData, "$(DIR)", "") sData = Replace(sData, "$(STYLE)", "style.css") sData = Replace(sData, "$(RIGHT)", "right") Endif File.Save(sDest, sData) End Public Sub Main() Dim sFile As String Dim sDir As String Dim sLang As String Dim aLang As String[] Dim sTrans As String Dim sData As String Dim iPos, iPos2 As Integer InitVar ' Trick for directly modifying the project html files sDir = Application.Path &/ "gambas.sourceforge.net" ' For Each sFile In Dir(sDir, "*.template") ' Print sFile ' Expand(sDir &/ sFile) ' Next 'MChangeLog.MakeChangeLog(sDir, 2) 'MChangeLog.MakeChangeLog(sDir, 3) If Exist("~/gambas/2.0/trunk") Then Try Kill "~/gambas/2.0/trunk/app/src/gambas2/authors.txt" Copy "authors.txt" To "~/gambas/2.0/trunk/app/src/gambas2/authors.txt" Endif If Exist("~/gambas/3.0/trunk") Then Try Kill "~/gambas/3.0/trunk/app/src/gambas3/authors.txt" Copy "authors.txt" To "~/gambas/3.0/trunk/app/src/gambas3/authors.txt" Endif For Each sLang In $aLanguages aLang = Split(sLang, ":") $sLang = aLang[0] System.Language = aLang[1] sLang = $sLang For Each sFile In Dir(sDir, "*.template") Print sFile Expand(sDir &/ sFile) Next For Each sFile In Dir(sDir, "*.html") ReplaceMail(sDir &/ sFile) Next Try Mkdir sDir &/ sLang MTranslation.Load For Each sFile In Dir(sDir, "*.html") If sFile = "index.html" Then Continue Translate(sDir &/ sFile, sDir &/ sLang &/ sFile, sFile Like "changelog*.html") Next Next Print Print "Creating the translation module..." For Each sTrans In $cTrans sTrans = Replace(sTrans, "\"", "\\\"") sData &= " $cTr[\"" & sTrans & "\"] = (\"" & sTrans & "\")\n" Next sFile = File.Load(Application.Path &/ ".src/MTranslation.module") iPos = InStr(sFile, "'{") iPos2 = InStr(sFile, "'}", iPos) sFile = Left$(sFile, iPos - 1) & "'{\n" & sData & " '}" & Mid$(sFile, iPos2 + 2) File.Save(Application.Path &/ ".src/MTranslation.module", sFile) Print Print "**** DONE! ****" End