This project is read-only.

Documentation: Adding Easy Translate to an existing project

(For now, this is all documentation aviable, it will be expanded later)

The following steps depend on the type of your project. In most cases, it will be a windows forms project, with more than one form.
In that case, the following steps should be taken (this is all vb, because I didn’t find time to learn C# yet):

Add a project reference to Easy Translate

In the Solution Explorer, right click on your project and choose Properties.
On the left, choose References. Click Add and choose the Browse tab. Browse toward the location where you saved Easy Translate and click OK.

Create a language file

For each control on your form, you need to make an entry in your language file. Easy Translate comes with a generator for this, so you won’t have to type it all yourself, but can just call that one.
Private Sub Generate()
    Dim LanguageFileGenerator As New EasyTranslate.Generator
    Dim ControlNames(Me.Controls.Count) As String 'Store control names
    Dim ControlTexts(Me.Controls.Count) As String 'Store control text values
    Dim Control As Control 'Store current control

    For i As Integer = 0 To Me.Controls.Count - 1
        Control = Me.Controls(i)
        ControlNames(i) = Control.Name
        ControlTexts(i) = Control.Text
    Next
    If LanguageFileGenerator.Generate("C:\languagefile.lang", ControlNames, ControlTexts) = True Then
        MessageBox.Show("File succesfully generated.")
        System.Diagnostics.Process.Start("C:\languagefile.txt")
    End If
End Sub

Call this sub when your form starts up or so, and the language file will be created and opened. To translate it, just change the values, which you can see behind the ‘=’-mark.

Note: If you use ‘nested’ controls, such as panels and group boxes, you will have to change the Generate method in your form, because only the controls that are directly on your form will be in the me.controls array.

Add translation to your forms

In every form, add the following method:
Private Sub Translate(ByVal language As String)
    Static FirstTime As Boolean = True

    With EasyTranslate.EasyTranslate.SharedTranslator.Translator

        'Initialize if it's the first call to this method
        If FirstTime Then
            .Initialize("C:\")
            'Replace C:\ with the folder where you store your language files
            FirstTime = False
        End If

        If .Aviable(language) Then
            .ChangeLanguage(language) 'Change language to the specefied language
            'You must first change the language before you can acces the
            'texts associated with it.
        End If

        For Each control As Control In Me.Controls
            If .GetValue(control.Name) <> Nothing Then
                control.Text = .GetValue(control.Text)
            End If
        Next

    End With
End Sub

Now you can create an UI around it, and call the translate sub every time you want to change language.

Note: If you want to be able to add languages in runtime, you can by adding one to the language folder and calling the Initialize method.

Note: If you use ‘nested’ controls, such as panels and group boxes, you will have to change the Translate method in your form, because only the controls that are directly on your form will be in the me.controls array.

Last edited Nov 2, 2007 at 7:09 PM by Jouketje, version 4

Comments

Jouketje Nov 7, 2007 at 8:08 PM 
This works only for the newest release, 1.7. In version 1.6 there's no 'SharedTranslator' object, wich you have to create yourself.