Dear ppl,
I figured out a solution for the problem in the thread, its a combination of
all posts including this one http://forums.asp.net/1219973/ShowPost.aspx
:)
it?s not
that clean but I think it?s better than nothing and I like to share the idea
with you as you are more experienced, I?m going to tell you the situation how I
solved that.
Scenario:
1-Build a multilingual website using ASP.NET 2.0 for my company
2-MaterPage with a change language combo that is localized at the first request
of the page [suing asp.net 2.0 new browser request culture detection] and then
the user can change the language any time from the master page. [So the new
culture reflects all the website pages]
3-It?s
supposed that there are 3 languages, English, French and Arabic [Arabic needs
the pages to rendered in RTL L I did it but there is some issues]
I didn?t
put any code in the global.asax - Application_BeginRequest, I figured out a way for doing
that, thanks for the great hint of
Ran Davidovitz to use the helper class which actually is a class that inherits from a
webpage to add the InitializeCulture() , and then make
all site pages inhereit from this baseclass.
What I
did:
1-web.config
<globalization enableClientBasedCulture="true" culture="en-US" uiCulture="en-US" requestEncoding="utf-8" responseEncoding="utf-8" />
2-MasterPage:
Design:
a. Add the
global resource files under the App_GlobalResources folder:
AllSite.ar.resx
AllSite.resx
AllSite.ar.resx:
<data name="TextDirection" xml:space="preserve">
<value>RTL</value>
</data>
AllSite.resx:
<data name="TextDirection" xml:space="preserve">
<value>LTR</value>
</data>
b. HTML
direction attribute to be retrieved from a global resource to adjust page
direction [in case of English, French it will be LTR and Arabic will be RTL
<html runat="server" xmlns="http://www.w3.org/1999/xhtml"
dir='<%$ Resources:AllSite,
TextDirection %>'>
c.
localized label and combo for language selection
<td align="left">
<asp:Label ID="lblSelLang"
runat="server"
meta:resourcekey="lblSelLangResource1"
Text="Select your language:"></asp:Label>
</td>
</tr>
<tr>
<td align="left">
<asp:DropDownList ID="comboSelLanguage"
runat="server"
AutoPostBack="True"
meta:resourcekey="comboSelLanguageResource1"
OnSelectedIndexChanged="comboSelLanguage_SelectedIndexChanged">
<asp:ListItem meta:resourceKey="ListItemResource1">Choose
....</asp:ListItem>
<asp:ListItem meta:resourceKey="ListItemResource2"
Text="English"
Value="en"></asp:ListItem>
<asp:ListItem meta:resourceKey="ListItemResource3"
Text="Francais"
Value="fr"></asp:ListItem>
<asp:ListItem meta:resourceKey="ListItemResource4"
Text="???????"
Value="ar"></asp:ListItem>
</asp:DropDownList></td>
</tr>
Code: to
handle the language (culture selection) and then return the referrer page
protected void
comboSelLanguage_SelectedIndexChanged(object
sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("SelLang");
cookie.Value =
comboSelLanguage.SelectedValue;
Response.SetCookie(cookie);
Response.Redirect(Request.UrlReferrer.AbsoluteUri); // this is
for the redirecting to the referrer page
}
3-Build a BaseClass under the App_Code\BL forlder in your project ,that
all pages will inherit from.
Code:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Threading;
using
System.Globalization;
/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage :Page
{
public BasePage()
{
//
// TODO: Add constructor logic here
//
}
protected override void InitializeCulture()
{
string lang = string.Empty;//default to the invariant culture
HttpCookie cookie =
Request.Cookies["SelLang"];
if (cookie != null && cookie.Value != null)
{
lang = cookie.Value;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
}
base.InitializeCulture();
}
}
4-Build
the web pages [the will be in the content place holder in the master page] and
generate local resources, and DON?T FORGET INHERIT FROM THE BASEPAGE CLASS ;),
and add your local resources for them.
My Issues
is that some controls doesn?t render to RTL well , I don?t know why and what?s
going to drive me nuts is the same control (ex: asp:Label) renders sometimes
right and sometimes wrong .. I think there is a web design consideration that
should be taken or layout considerations to support both RTL and LTR languages;
I hope any one can help me in this area
Hope this
helps