0

I need to use labels, and also popups with text. This text needs to be translated in any language, and that's what I did, using a database reference of translations in various .resx files: any label/object has its ID, which I associate the translation, then with a combobox I select the languages that do the translation.

With the labels of the form that contains the combobox no issues, Since I'm using a SwitchCase that calls out translating functions:

Private Sub LangSelector_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LangSelector.SelectedIndexChanged
    With LangSelector.Items
        Select Case Me.LangSelector.SelectedIndex
            Case Is = 0
                SetItalian()
            Case Is = 1
                SetEnglish()
            Case Is = 2
                SetFrench()
            Case Is = 3
                SetSpanish()
            Case Is = 4
                SetItalian()
        End Select
    End With
End Sub

And translating functions...

Public Sub SetItalian()
        OpacityLabel.Text = My.Resources._0_ITA_LangText_ScaffPanel.OpacityLabel
        optIta.Text = My.Resources._0_ITA_LangText_ScaffPanel.optIta
        optEng.Text = My.Resources._0_ITA_LangText_ScaffPanel.optEng
    optEsp.Text = My.Resources._0_ITA_LangText_ScaffPanel.optEsp
    LangSelector.TabIndex = 0(My.Resources._0_ITA_LangText_ScaffPanel.optIta)

End Sub

Those resx elements are tables with label/radio button's ID elements with associated text. With the elements where there is the combobox (UserControl) no issues. Problems are facing with the elements in another UserControl... How do I tell the elements are available to be translated?

And also, I don't know how to change text inside a popup, for the sake of translation (it's a tooltip).

How do I also change text in the combobox properly for the same translation purposes?

robni
  • 904
  • 2
  • 6
  • 20
ErCapoAlex
  • 15
  • 2

1 Answers1

1

Is the comboBox nescessary? Can't you let the Current Culture decide which language to use?

My VB.Net is a bit rusty but I think this should work similar to how you would do it in C#, see How to use localization in C#

The link goes in to a lot more details on how to do this, it's tagged as C# but I think it wouldn't be hard to make it work in VB.

Essentially, create a resource file e.g. strings.resx for your primary language which it sounds like you have done, ensure you always assign every bit of text to your controls from that.

Add all your languages as a new resource file with the language name in it. e.g. strings.it.resx and you wan't need to change a line of code if you want to add more languages later.

Does this help?

Private Sub LangSelector_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LangSelector.SelectedIndexChanged
    With LangSelector.Items
        Select Case Me.LangSelector.SelectedIndex
            Case Is = 0
                SetLanguage("it")
            Case Is = 1
                SetLanguage("en")
            Case Is = 2
                SetLanguage("fr")
            Case Is = 3
                SetLanguage("es")
            Case Is = 4
                SetLanguage("it")
        End Select
    End With
End Sub

Private Sub SetLanguage(language as String)
  Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language);
  For Each (Control c in ???.Controls)
    If c.GetType == typeof(YourType)
      (CType(c,YourType)).UpdateLanguage()
    End If
  Next
End Sub

Matt
  • 1,436
  • 12
  • 24
  • First of all, thanks a lot for your reply. The issue is that I can't retrieve the object from user control A to user control B. I can change text from comboBox Selector User Control A to User Control A, but not from comboBox selector User Control A to User Control B :( – ErCapoAlex Jun 30 '22 at 19:05
  • Unfortunately I can't use localization, because I'll also need to refer in a future version to a LISP AutoCAD variable that tells me which language I'm using (It's a tool palette for AutoCAD) – ErCapoAlex Jun 30 '22 at 19:08
  • This LISP variable, which works in AutoCAD environment, gives values "0, 1, 2, ..." per the language selected (0 = Italian, 1 = English, and so on) so future language change will depend on it, and not by the combobox, when I'll be able to make it work. The issue stays for now regarding the communication between U.C. A to U.C. B. I have combobox for langchange in A, I need to retrieve text label ID string that stays in B and from U.C. A combobox change it – ErCapoAlex Jun 30 '22 at 19:11
  • Added a code example that might help. You would need a method on each one of your user controls called UpdateLanguage. Sorry if it's not VB.Net compliant, but I'm very rusty as moved to C# years ago. – Matt Jul 01 '22 at 19:28
  • hey man thanks a lot. so that code inside the other user control should bypass that communication limit between form a and b? – ErCapoAlex Jul 01 '22 at 19:47