VB.NET

Dec 13, 2010 at 1:36 PM

Hi,

does it work for VB.NET?

 

Regards, Tom

Coordinator
Dec 14, 2010 at 9:06 PM
Edited Dec 14, 2010 at 9:11 PM

I didn't test NLocalizer with VB.NET, but I think it should work fine. Translation will be compile in runtime as C# language and will cooperate with compiled VB.NET assembly.

If any problems, please give me information.

Dec 15, 2010 at 2:24 PM

I've spent hours but I couldn't get it to work.

Maybe you could have a look at it. It's a very, very simple example.

You can download it here: http://rapidshare.com/files/437087324/NLocalizerVB.zip.

In the form load event I have:      

Translator.Translation.Read()
For Each lang As KeyValuePair(Of String, TranslationClasses) In Translator.Translation
    listbox.Items.Add(lang.Key)
Next
Translator.Translate(Me)
The "translate" produces compile errors.

 

Thanx, Tom

Coordinator
Dec 15, 2010 at 6:19 PM
Edited Dec 15, 2010 at 6:29 PM

I figure out what's going on in Your example and... it's working fine :)

Deutsch.lang:

module System.dll, System.Windows.Forms.dll, NLocalizer.dll, NLocalizerTest.exe
using System, System.Windows.Forms, System.Reflection, NLocalizer, NLocalizerTest
static Messages,
(frmMain)AAAToolStripMenuItem.Text = Oeffnen
(frmMain)BeendenToolStripMenuItem.Text = Beenden
(frmMain)btnEnglish.Text = Englisch
(frmMain)btnGerman.Text = Deutsch
(frmMain)Button1.Text = Und ein Knopf
(frmMain)Button2.Text = Beenden
(frmMain)DateiToolStripMenuItem.Text = Datei
(frmMain)InfoToolStripMenuItem.Text = Info
(frmMain)Label1.Text = Das ist ein Label
(frmMain)Label2.Text = Sprache:
(frmMain)MenuStrip1.Text = MenuStrip1
(frmMain)SpeichernToolStripMenuItem.Text = Speichern
(frmMain)Text = NLocalizer-Test (D)
(frmMain)UeberToolStripMenuItem.Text = Ueber
(Messages)MyFirstMessage = Deutsh first message

frmMain.vb:

Imports System.IO
Imports NLocalizer

Public Class frmMain
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("Hier steht der Meldungstext")
    End Sub

    Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGerman.Click
        Translator.Translate("Deutsch", Me)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnglish.Click
        Translator.Translate("English", Me)
    End Sub

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Translator.Translation.Read()
        For Each lang As KeyValuePair(Of String, TranslationClasses) In Translator.Translation
            lb.Items.Add(lang.Key)
        Next
        Translator.Translate(Me)
    End Sub
End Class

Please remember, than all controls must be public not friend (modifier property). Current version of NLocalizer require Messages class. Next version of NLocalizer will be more friendly. If You have any question, give me information.

Your compiled example: NLocalizerVB.zip

 

Coordinator
Dec 15, 2010 at 6:50 PM
Edited Dec 15, 2010 at 6:51 PM

You can use Messages.vb (Messages class):

Public Class Messages
    Public Shared MyFirstMessage As String = "Hier steht der Meldungstext"
End Class

and then in frmMain.vb:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    MsgBox(Messages.MyFirstMessage)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGerman.Click
    Translator.Translate("Deutsch", Me)
    Translator.Translate("Deutsch")
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnglish.Click
    Translator.Translate("English", Me)
    Translator.Translate("English")
End Sub
Dec 16, 2010 at 6:47 AM

Great! I've made it.

The magic thing was, that all languages file need the bold-marked additions:

module System.dll, System.Windows.Forms.dll, NLocalizer.dll, NLocalizerTest.exe
using System, System.Windows.Forms, System.Reflection, NLocalizer, NLocalizerTest
static Messages,

I've converted the vb-file to c# and imported it with NLocalizerApp.exe. And this did not create what I've mentioned above.

Anyway - it works.

I've compared all tools an projects that are avaliable for free. Yours is the best, because it's the most easy to use. Thank you for sharing it. I'm looking forward to your improvements.

Regards, Tom

 

Coordinator
Sep 2, 2011 at 3:15 PM
Edited Sep 2, 2011 at 3:16 PM

NLocalizer 1.7+ don't need special line like module or using because it autodetect necessary libraries. Static classes also may be not marked by static word (static messages may be marked by !). Visual Basic.NET example included.