Question Globalization Question?

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I add Turkish,English and Greek languages to my masterpage in order to change labels on my web forms.But the problem is, i just want to change labels, button names, error messages NOT the dates etc. Here is what i changed;

masterpage.master
VB.NET:
<asp:DropDownList ID="ddlLanguage" runat="server" OnSelectedIndexChanged="ddlLanguage_SelectedIndexChanged"
                AutoPostBack="true">
                <asp:ListItem Text="Turkish" Value="tr-TR" />
                <asp:ListItem Text="English" Value="en-US" />
                <asp:ListItem Text="Greek" Value="el-GR" />
            </asp:DropDownList>

masterpage.master.vb
VB.NET:
Protected Sub ddlLanguage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        'Sets the cookie that is to be used by Global.asax

        Dim cookie As HttpCookie = New HttpCookie("culture")
        cookie.Value = ddlLanguage.SelectedValue
        Response.Cookies.Add(Cookie)

        'Set the culture and reload the page for immediate effect. 
        'Future effects are handled by Global.asax


        Dim ci As New System.Globalization.CultureInfo(cookie.Value)
        System.Threading.Thread.CurrentThread.CurrentCulture = ci
        System.Threading.Thread.CurrentThread.CurrentUICulture = ci

        Server.Transfer(Request.Path)



    End Sub

global.asax
VB.NET:
    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

        Dim cookie As HttpCookie
        cookie = Request.Cookies.Get("culture")
        If (Not cookie Is Nothing) Then

            Dim ci As New System.Globalization.CultureInfo(cookie.Value)
            System.Threading.Thread.CurrentThread.CurrentCulture = ci
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci
        Else
            Dim ci As New System.Globalization.CultureInfo("tr-TR")
            System.Threading.Thread.CurrentThread.CurrentCulture = ci
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci

        End If

    End Sub

contentpage.aspx
VB.NET:
<asp:Label ID="Label7" runat="server" Text="<%$ Resources:Content, Label7 %>"></asp:Label>

Also Content.resx , Content.en.resx and Content.el.resx files are generated in App_GlobalResources.

The code works but as i explained, when i changed to Turkish (native language), to English or Greek, labels change correctly but when i try to insert into DB, it gives error due to date!!! I just want to change labels etc., i dont want to change dates and numbers etc.

Any help would be great.

Thanks in advance.

Best Regards
 
Here is the error message when i try to submit the form after changing language from Turkish to English

Conversion from string "23/09/2010" to type 'Date' is not valid.
 
If you don;t want to use the options for a specific culture then you can't use that specific culture. If you want to use custom options then you'll need to create a custom CultureInfo.
 
I wrote something like below to my content.aspx.vb and worked.


Dim cookie As HttpCookie
cookie = Request.Cookies.Get("culture")
Dim fmt As DateTimeFormatInfo
Dim sDate As DateTime
Dim eDate As DateTime
If (Not cookie Is Nothing) Then
If (Not cookie.Value = "tr-TR") Then
fmt = New System.Globalization.DateTimeFormatInfo()
fmt.ShortDatePattern = "dd/MM/yyyy"
sDate = DateTime.ParseExact(TextBox_baslangict.Text, "d", fmt)
eDate = DateTime.ParseExact(TextBox_bitist.Text, "d", fmt)
Else
sDate = TextBox_baslangict.Text
eDate = TextBox_bitist.Text
End If
End If

But now the problem is, when navigate from content.aspx to success.aspx, gblobalization does NOT work. I m navigating from code behind.

strURL = "successPage_test.aspx?message=" + GeneralFunctions.encryptQueryString("Transaction OK.")
Response.Redirect(strURL)

When Success.aspx opens, label on page is in Turkish. But it was English on Content.aspx when i redirect it to Success.aspx. Is there a way to keep this language settings for all my pages?

Best Regards
 
The code works but as i explained, when i changed to Turkish (native language), to English or Greek, labels change correctly but when i try to insert into DB, it gives error due to date!!! I just want to change labels etc., i dont want to change dates and numbers etc.
A Date value does not have any culture dependency, often such problems are due to converting the dates to culture dependent string representations.
 
Back
Top