Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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 !!!

Edited by scalf

Scalf.

Do not want others to know what you have done? Better not have done it anyways.

  • Moderators
Posted

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)

Visit...Bassic Software
  • *Experts*
Posted

You might also give this a try...

       If Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName = "en" Then
           MessageBox.Show("English")
       ElseIf Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName = "fr" Then
           MessageBox.Show("French")
       End If

or

       If Thread.CurrentThread.CurrentCulture.DisplayName = "English" Then
           MessageBox.Show("English")
       ElseIf Thread.CurrentThread.CurrentCulture.DisplayName = "France" Then
           MessageBox.Show("France")
       End If

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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.

Scalf.

Do not want others to know what you have done? Better not have done it anyways.

  • Moderators
Posted

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)

 

Visit...Bassic Software
Posted

Thanks Robby, this is an interesting trick ;) , It works fine !

 

and that's what I did in my PageLoad.

Scalf.

Do not want others to know what you have done? Better not have done it anyways.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...