Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello all i have a website in vb.net.i want to make my website globalized for this i have a webpage Default.aspx in this page i take a dropdown in which there is several languages when i select the language from the dorpdown and clicking on the button the text are converted into the selected language.to acheive this i write the code in .vb file is as follows


Imports System.Resources
Imports System.Globalization
Imports System.Threading

Partial Class _Default
    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As System.Object, _
             ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            drpLanguages.Items.Add(New  _
              System.Web.UI.WebControls.ListItem("English", "en-NZ"))

            Dim sLang As String = "en-NZ"
            SetCulture(sLang)
        End If
    End Sub
    Private Sub SetCulture(ByVal sLang As String)
        Dim gStrings As String
        Thread.CurrentThread.CurrentUICulture = New CultureInfo(sLang)
        Thread.CurrentThread.CurrentCulture = _
                 CultureInfo.CreateSpecificCulture(sLang)
        p1.InnerHtml = gStrings.GetString("p1")
        btnlang.Text = gString.GetString("btnlang")

    End Sub
   
  
    Protected Sub btnlang_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnlang.Click
        Dim sLang As String = drpLanguages.SelectedItem.Value
        SetCulture(sLang)

    End Sub
End Class



and also add a .vb file named as Webform1 and the code is as folows----

Imports Microsoft.VisualBasic
Imports System.Resources
Imports System.Globalization
Imports System.Threading


Public Class Webform1
    Protected gStrings As New  _
ResourceManager("SatelliteAssemblies.Default", _
GetType(Webform1).Assembly)
End Class


but the problem is when i run this age the error is
""name gStrings is not declare."

please help me out what should i do to overcome from this problem.

should i made and initialization on page_load .

i make all the resourse file.

thanks and regard
subiya ahsan
Posted
Updated 2-May-11 20:13pm
v2
Comments
Ankit Rajput 3-May-11 2:14am    
EDIT: Code block added to the post

try this

protected override void InitializeCulture()
{
    culture = "fr-FR";
    UICulture = culture;
    Culture = culture;
    //OR This
    if (culture != "Auto")
    {
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
        System.Threading.Thread.CurrentThread.CurrentCulture = ci;
        System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
    }
    base.InitializeCulture();
}
 
Share this answer
 
use ResourceManager Directly to assign values to btnlang and p1 controls.
 
Share this answer
 
Comments
ahsan.subiya 4-May-11 0:32am    
how can i do this can u plz tell me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900