Click here to Skip to main content
15,070,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page (contactus.aspx) in my web site which is in VB.Net and that page has only static data. I want that all the static data is converted into the arabic language. For this I added an App_LocalResources folder in my web site and in that folder I added a Resource file named as 'contactus.aspx.ar.resx'. But it still shows static data on that page in English.

Please could you offer some guidance in how I might overcome this problem?
Do I need to add some code in contactus.aspx.vb file?
Posted
Updated 11-Apr-11 22:37pm
v2
Comments
R. Giskard Reventlov 12-Apr-11 4:38am
   
What have you already tried?

You need to make sure that:

1. You're referencing the resources correctly in the markup of contactus.aspx
2. You're setting the CurrentUICulture correctly

Some Links that may help:

http://msdn.microsoft.com/en-us/library/ms228208.aspx[^]

http://msdn.microsoft.com/en-us/library/bz9tc508.aspx[^]
   
make a folder Name "localization Test" in visiual studio 2008 or any

Step 1:
add a aspx page name Test1

the code behind


VB
Partial Class localizatioin_test_page1

    Inherits BasePage

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("lang") = 1 Then
            Session("lang") = 2
        Else
            Session("lang") = 1
        End If

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Session("lang") = 1
        End If

    End Sub

End Class



the html

XML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="page1.aspx.vb" Inherits="localizatioin_test_page1" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Label ID="Label1" runat="server" Text="value1"
            meta:resourcekey="Label1Resource1"></asp:Label>
        <br />
        <asp:Label ID="Label3" runat="server" Text="value2"
            meta:resourcekey="Label3Resource1"></asp:Label>
        <br />
        <asp:Label ID="Label2" runat="server" Text="value3"
            meta:resourcekey="Label2Resource1"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Change Lang"
            meta:resourcekey="Button1Resource1" />

    </div>
    </form>
</body>
</html>



Step 2:

Note: with code behind and html the page is ready.
Note: in code behind we are using Inherits BasePage

make a class name BasePage and put the code given below and put the BasePage in App_Code folder.
VB
Imports Microsoft.VisualBasic
Imports System.Data
Public Class BasePage
    Inherits Page
    Protected Overloads Overrides Sub InitializeCulture()
        Dim culture As String = String.Empty
        If Session("lang") = "1" Then
            culture = "ar-EG"
        Else
            culture = "en-US"
        End If

        If (String.IsNullOrEmpty(culture)) Then
            culture = "Auto"
            'Use this
            UICulture = culture
            culture = culture
        End If
        'OR This
        If (culture <> "Auto") Then
            Dim ci As New System.Globalization.CultureInfo(culture)
            System.Threading.Thread.CurrentThread.CurrentCulture = ci
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci
        End If
        MyBase.InitializeCulture()
    End Sub
End Class



Step 3: goto page test1 and tool-> generate local resources
it will create a folder named App_LocalResources and a local resource file named page1.aspx.resx
copy the page1.aspx.resx and paste in same folder and rename as page1.aspx.ar.resx

now you have two files
1. page1.aspx.resx
2. page1.aspx.ar.resx

page1.aspx.resx is original one and translate page1.aspx.ar.resx in arabic

run the page it will work
   
Comments
ahsan.subiya 12-Apr-11 8:05am
   
sir did the same as you said.the page is runni ng without any error bt the output is only

value1
value2
value3
when i click on the button nothing happend


please tell what your code is doing.
thanks and regard
subiya ahsan

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