Question

I managed to translate my WPF application during runtime, but strings in .resx won't translate.

I have a Login.resx and Login-pt.resx, both have a "prueba" entry with different values, but they always load the default resx (Login.resx).

Private Sub btnAr_Click (sender As System.Object, e As System.EventArgs) Handles btnAr.Click
    Thread.CurrentThread.CurrentCulture =
        CultureInfo.CreateSpecificCulture("es-AR")
    Thread.CurrentThread.CurrentUICulture = New CultureInfo("es-AR")
    ChangeLanguage("es-AR")
    MessageBox.Show(Login.Prueba)
End Sub


Private Sub btnPt_Click(sender As System.Object, e As System.EventArgs) Handles btnPt.Click
    Thread.CurrentThread.CurrentCulture =
      CultureInfo.CreateSpecificCulture("pt-BR")
    Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-BR")
    ChangeLanguage("pt-BR")
    MessageBox.Show(Login.Prueba)
End Sub

Private Sub ChangeLanguage(ByVal lang As String)
    For Each c As Control In Me.Controls
        Dim resources As ComponentResourceManager = New     ComponentResourceManager(GetType(LoginUsuario))
        resources.ApplyResources(c, c.Name, New CultureInfo(lang))
    Next c
End Sub

Thanks!

Was it helpful?

Solution

I think your resource name Login-pt.resx is wrong. It should be Login.pt.resx or Login.pt-BR.resx.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top