HELP Pretty please :-)

R

Robert Dufour

I am trying to localize a very simple web site (english and french)

I have a master page and one content page for now.
On the master page I have placed a Localize control

On the content page I have placed a label and a dropdownlist. The label says
"Use this language" or "Utilisez cette laague"
The dropdownlist Contains values "en-US" text Englsih Us and "fr-CA" text
"French Canada)

I have resource files for the master page in english and french with a key
saying "welcome" value Welcome in english and Bienvenue in french resource
file. They are local resource files for the master.

The objective is to allow the user to switch languages by settting the
current threads UiCulture and Culture in code when the user selects another
language. When he -she changes language in the dropdown list , the content
of the master file localize control should change and the contents of the
content page should change.

I've been f.. around with this one for over two days but I can't get it
working.
I have based my code on the code in the sample video on msdn for
localization but in this case just extending it to work with a master page
I've hit a brick wall :-(

Can someone PLEASE, prety please give a hand on this one.

This is the code I've come up with so far

1- the master page, just a standard masterpage with one localized control on
it.

<%@ Master Language="VB" %>

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

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Localize ID="LocWelc" runat="server" meta:resourcekey="Welcome"
Text="Welcome"></asp:Localize><br />

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>

</div>

</form>

</body>

</html>



2- The content page - standard page with default culture and Uiculture set
tp fr-CA

<%@ Page Language="VB" MasterPageFile="~/Site.master"
AutoEventWireup="false" CodeFile="Default3.aspx.vb"

Inherits="Default3" Title="Untitled Page" Culture="fr-CA"
UICulture="fr-CA"%>

<%-- Add content controls here --%>

<asp:Content runat="server" ID="d3C"
ContentPlaceHolderID="ContentPlaceHolder1"

EnableViewState="true">

<asp:Label ID="Label1" runat="server" Text="<%$ Resources:Label1.Text
%>"></asp:Label>

<asp:DropDownList ID="Language1" runat="server" AutoPostBack="True"
Width="149px">

<asp:ListItem Value="fr-CA">Français (Canada)</asp:ListItem>

<asp:ListItem Value="fr-FR">Français (France)</asp:ListItem>

<asp:ListItem Value="en-CA">English (Canada)</asp:ListItem>

<asp:ListItem Value="en-US">English (US)</asp:ListItem>

</asp:DropDownList>

</asp:Content>



3- The code behind of the content page

Imports System.Threading

Imports System.Globalization

Partial Class Default3

Inherits System.Web.UI.Page

Protected Overrides Sub InitializeCulture()

If Request.Form.Item("Language1") IsNot Nothing Then

Dim Lang As String = Request.Form.Item("language1")

Thread.CurrentThread.CurrentCulture = _

CultureInfo.CreateSpecificCulture(Lang)

Thread.CurrentThread.CurrentUICulture = New _

CultureInfo(Lang)

End If

End Sub

End Class

All the controls on both master and content page have had their expressions
text property set to point to the appropriate key in the resource file.

The main problem appears to be that no matter what, when I change the
selection in the drop down list the variable Request.Form.Item("Language1")
always returns nothing I can never obtain the value of the dropdownlist
selected item.

I can get it to detect the selected language if I detect it in the selected
index changed event of the language1 control but this event fires well after
the Initialize culture event, so If I use that I am always using the
previously selected item not the one that is currently being selected.

The technique described above with the code in the code behind works OK in
a stand alone content page but it fails miserably when you make a content
page that uses a master page. I have not been able to find any sample code
on how to use this with master pages.

The second part of the question, sorry if its long, is how do you change the
value of the localize control on the master page when the user selects
another language in the content page?

I am realy desperate and would really appreciate any help anyone would be
kind enough to give

Thanks you in advance to all

Bob
 
C

Cowboy \(Gregory A. Beamer\)

Check where you have the resource files. It matters.

I would read Michele Bustamante's first article for more info on
meta:resourcekey versus attaching resources using other declarative means of
linking to local/global resources.
http://msdn2.microsoft.com/en-us/library/aa478974.aspx

This article is also great if you want to move to external resources or
database:
http://msdn2.microsoft.com/en-us/library/aa905797.aspx

Her blog (www.dasblonde.com) has some great globalization/localization
posts.
 
R

Robert Dufour

I've read the article and been to her web site seing the globalization
samples and copied and studied the web one , but I still don't see why the
line
Request.Form.Item("Language1") always returns nothing when used in a web
site with master page but detects the control value OK when a master page
is not involved.
That seems to be the crux of the problem, the code does not find the control
Language1 on the web page, when its in a page that uses a master but it
finds it OK in a simple web page. Why and how to fix it?
Thanks
Bob
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

View the source of the page in the browser, and you will see that the
name of the field is not what you expected. When a control is inside a
container like the Content control, it's id is changed to ensure that
it's unique.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top