Form1.Caption=;-) FredJust Translate DEMO BTend.Caption=Sortir BTend.ToolTipText=Quitter le programme BTok.Caption=Bonjour tout le monde OP(2).Caption=trois OP(2).ToolTipText=Choix N°3 OP(1).Caption=deux OP(1).ToolTipText=Choix N°2 OP(0).Caption=un OP(0).ToolTipText=Choix N°1 MNfile.Caption=Fichier MNfileNew.Caption=Nouveau MNfileOpen.Caption=Ouvrir MNfileSave.Caption=Enregistrer MNfileSaveAS.Caption=Enregistrer sous ... MNfileExit.Caption=QuitterAfter translation of left parts procedure LoadAllName is going to change all this wording by using a temporary collection containing translations
Private Sub Form_Load() With Translation .Add "Bonjour comment ca va aujourd'hui", "Bonjour comment ca va aujourd'hui" .Add "Etes vous sur", "Etes vous sur" .Add "Si vous voulez traduire ce programme dans un autre langage,", "Si vous voulez traduire ce programme dans un autre langage," .Add "ouvrez un fichier .LNG (du répertoire de l'application) avec un editeur de texte,", "ouvrez un fichier .LNG (du répertoire de l'application) avec un editeur de texte," .Add "traduisez les lignes du fichier et enregistrez le sous un autre nom.", "traduisez les lignes du fichier et enregistrez le sous un autre nom." .Add "La version francaise est de fredjust@hotmail.com", "La version francaise est de fredjust@hotmail.com" End With End SubThis collection will be also protected in the file.
Public Function Translate(sentence As String) As String On Error Resume Next Translate = Translation(sentence) If Err.Number <> 0 Then Translate = sentence FunctionIf translation exists in the collection she(it) will be posted(shown) in the place otherwise original sentence will be posted(shown).
( Sources converts in 6 colours with my VB TO HTML program)
'=============================================================================== ' send comments to ' fredjust@hotmail.com ' http://fred.just.free.fr/ '=============================================================================== ' Add a "Microsoft scripting runtime" REFERENCE only on VB6 Public FSO As New FileSystemObject Public TextStream As TextStream Dim Tempo As String Dim Obj As Control Dim phrase Dim CaptionCollection As Collection Dim ObjIndex As Long Public Translation As New Collection '================================================================================== ' Save all caption, tooltiptext, and Sentences of the Translation collection '================================================================================== Public Sub SaveAllName(ByVal aForm As Form, ByVal FileName As String) On Error Resume Next ' Create the text file Set TextStream = FSO.CreateTextFile(App.Path & "\" & FileName, True) ' write produc name TextStream.WriteLine "[" & App.Title & "] don't translate this line and the name before '='" ' write the caption of form TextStream.WriteLine aForm.Name & ".Caption=" & aForm.Caption For Each Obj In aForm Tempo = "" Err.Clear ObjIndex = Obj.Index If Err.Number <> 0 Then ' if the object is not indexed Tempo = Obj.Caption If Tempo <> "" Then ' write Caption of the object TextStream.WriteLine Obj.Name & ".Caption=" & Tempo End If Tempo = "" Tempo = Obj.ToolTipText If Tempo <> "" Then ' write ToolTipText of the object TextStream.WriteLine Obj.Name & ".ToolTipText=" & Tempo End If Else ' if the object is indexed Tempo = Obj.Caption If Tempo <> "" Then ' write Caption of the object TextStream.WriteLine Obj.Name & "(" & Obj.Index & ").Caption=" & Tempo End If Tempo = "" Tempo = Obj.ToolTipText If Tempo <> "" Then ' write ToolTipText of the object TextStream.WriteLine Obj.Name & "(" & Obj.Index & ").ToolTipText=" & Tempo End If End If Next ' End of this section IMPORTANT it's use in the LOAD function TextStream.WriteLine "[END CAPTION] - don't translate this line" ' write all sentence For Each phrase In Translation TextStream.WriteLine phrase & "=" & Translation(phrase) Next TextStream.Close End Sub '================================================================================== ' Load and change Caption and toolTipText '================================================================================== Public Sub LoadAllName(aForm As Form, FileName As String) Dim BeginName As Long On Error Resume Next ' open the text file Set TextStream = FSO.OpenTextFile(App.Path & "\" & FileName, ForReading) 'clear the collection Set CaptionCollection = New Collection Tempo = TextStream.ReadLine ' is the file is for this application ? If InStr(1, Tempo, App.Title) = 0 Then MsgBox "The file is invalid !" Set CaptionCollection = Nothing TextStream.Close Exit Sub End If ' caption form on the 2° line Tempo = TextStream.ReadLine BeginName = InStr(1, Tempo, "=") aForm.Caption = Mid(Tempo, BeginName + 1) Tempo = TextStream.ReadLine ' read all caption and tooltiptext which are in the file While InStr(1, Tempo, "[END CAPTION]") = 0 And Err.Number = 0 BeginName = InStr(1, Tempo, "=") CaptionCollection.Add Mid(Tempo, BeginName + 1), Mid(Tempo, 1, BeginName - 1) Tempo = TextStream.ReadLine Wend ' no error (we found [END CAPTION] in the file) If Err.Number = 0 Then For Each Obj In aForm Err.Clear ObjIndex = Obj.Index 'if the objet is indexed If Err.Number = 0 Then ' change caption of object Obj.Caption = CaptionCollection(Obj.Name & "(" & Obj.Index & ").Caption") ' change tooltiptext of object Obj.ToolTipText = CaptionCollection(Obj.Name & "(" & Obj.Index & ").tooltiptext") Else ' change caption of object Obj.Caption = CaptionCollection(Obj.Name & ".Caption") ' change tooltiptext of object Obj.ToolTipText = CaptionCollection(Obj.Name & ".tooltiptext") End If Next ' clear the translation collection Set Translation = New Collection Do Tempo = TextStream.ReadLine BeginName = InStr(1, Tempo, "=") Translation.Add Mid(Tempo, BeginName + 1), Mid(Tempo, 1, BeginName - 1) Loop Until TextStream.AtEndOfStream Else MsgBox "The file is invalid !" End If TextStream.Close Set CaptionCollection = Nothing End Sub '=============================================================================== ' return the translation of a sentence ' if it doesn't exist the sentence wasn't translate '=============================================================================== Public Function Translate(sentence As String) As String On Error Resume Next Translate = Translation(sentence) If Err.Number <> 0 Then Translate = sentence Function