Selection of CultureInfo

scalf

Freshman
Joined
Jun 15, 2004
Messages
25
Location
FRANCE
Hello,

I'm still trying to setup my multilinguage display in my webform and after having solved my problem of resource file compilation I'm expreriencing a new problem :

I created two resource files : one is named "strings.fr-FR.resx" for french culture and the other is named "strings.en-US.resx" for english culture. I put in the two files differente labels in french and english and I initialised my webform with the code below :

Public rm As ResourceManager
Public ciFR As New CultureInfo("fr-FR")
Public ciEN As New CultureInfo("en-US")


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Session("language") = "English" Then

Thread.CurrentThread.CurrentCulture = ciEN

Else
Thread.CurrentThread.CurrentCulture = ciFR

End If

rm = New ResourceManager("Auditeurs_user.strings", Me.GetType.Assembly.GetExecutingAssembly)

If Not Page.IsPostBack Then
initpage()
End If
End Sub


My problem is that anything I do, it's always the french culture which is chosen and my web page always displays the same french labels.

If someone has an idea about how to switch from one culture to another.

PS : the Session("language") = "English" is initialized when I click on an English flag button and the string value "English" is saved in a session varaible.

Merci Beaucoup !!!
 
Last edited:
I would use a helper function such as the following...

PublicFunction GetLangString(ByVal name AsString) AsString
Dim info As CultureInfo = New CultureInfo(culture_string)
Return rm.GetString(name, info)
EndFunction

Call the mthod with something like this....
homeTextbox.Text = GetLangString("myHomeMessage")

and set the 'culture_string' when you instantiate the class or with the value of your Session("Language") variable ("en-US)
 
You might also give this a try...
Visual Basic:
        If Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName = "en" Then
            MessageBox.Show("English")
        ElseIf Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName = "fr" Then
            MessageBox.Show("French")
        End If
or
Visual Basic:
        If Thread.CurrentThread.CurrentCulture.DisplayName = "English" Then
            MessageBox.Show("English")
        ElseIf Thread.CurrentThread.CurrentCulture.DisplayName = "France" Then
            MessageBox.Show("France")
        End If
 
Many Thanks,

I didn't try the different solutions you gave me. I just added the following line code :

Thread.CurrentThread.CurrentUICulture = ciFR

in the condition where the french flag is clicked

and

Thread.CurrentThread.CurrentUICulture = ciEN

in the condition where the english flag is clicked



NB: ciFR is declared as Public CultureInfo("fr-FR")
ciEN is declared as Public CultureInfo("en-US")

I'll write down the different solutions you gave me, it may help.

Thanks for all.
 
Another thing, instead of always checking on which laguage to display anything simply change the entire thread to follow the desired culture...

Thread.CurrentThread.CurrentCulture = New CultureInfo(YourCultureString)

 
Back
Top