Last post Nov 29, 2008 03:30 PM by saedh
Nov 24, 2008 03:19 PM|saedh|LINK
Currently, I'm working on a bilingual Web Application (English/Arabic), which I'm utilising VS 2005 to develop. So far so good except when began attempting to Arabise Controls, such as Calendar.
To start with, the Default page displays a couple of radio buttons to select from:
Arabic or English. Selected language is then used to set working Culture of the Application. According to what I read on MSDN, I only have 2 options to set Culture: either through Web.cofig which will make it the default Culture
across entire Application, or by declaring so for each page. Unfortunately, I need none of that. What I'm seeking after is to set the Culture AFTER user selection then make it 'global' across entire Application; i.e. for all Pages.
Thread.CurrentThread.CurrentCulture = New CultureInfo("ar-OM", False)
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ar-OM", False)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ar-OM", False)
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ar-OM", False)
Gladly, both worked. However, as soon as I proceed to next page (Response.Redirect()), Culture is set back to English as the CurrentThread is presumably lost. After considerable time trying all possible workarounds, I became almost certain that there is
NO WAY to programmatically set Culture and keep it persistent for all pages without the need to declare such for every page. If I'm wrong (I hope), please show me how?
My workable workaround was to store selected language in a session variable then pass it to the next page, which I set to be a Master page, where I declared relevant Culture accordingly. Since ALL pages of my Application will use the Master page, they will
be subsequently influenced by Master set Culture. As I said, the workaround is working fine and both Layout and Content switch direction (& Format) as desired. Thanks to resource files, Controls are fully Arabised as well.
Speaking of Controls, I use a Calendar. Eventually, I managed to have Month and Day names appear in Arabic. The problem is with Abbreviated Day Names. In English, I use
FirstLetter as the format of Day Headers. Regretfully, I realised that such format (i.e. FirstLetter) is not supported in Arabic Calendar, not even any shortened format--just the full name, which has the 'ال'
(AL) prefix for all days (e.g. 'السـبت' ,'الأحـد', etc). Attempting to implement
DayNameFormat.FirstLetter resulted in displaying the letter 'ا' (Alef) for all days. I only want the first letter WITHOUT the prefix. Tried combining
Trim with Replace to get rid of the prefix then use first letter but it didn't work for me. I could be wrong as I'm new to VB and .NET environment.
Nov 24, 2008 03:52 PM|anas|LINK
Is there a way to programmatically set Culture and make it sustainable for all Pages, without the need to configure Web.config?
The asp.net is stateless , which means that the CurrentThread will be created for each request , and so you must apply the culture every time ,
You can do that by placing the mentioned code in the master Page page_load handler , without the need to use session, Or you
can create a Base Page class and change your pages to inherit from it .
How to get the first letter of Arabic Week Days ignoring the AL prefix?
Nov 24, 2008 04:18 PM|saedh|LINK
Wow... That was quick Anas.
You can do that by placing the mentioned code in the master Page page_load handler , without the need to use session
This is precisely what I've accomplished. However, I needed the Session to pass selected language from Default (+Login) to Master page, unless you suggest another technique I'm not aware of, which I will be more than pleased to know. To tell the truth, I'm
not that much happy by using Session or even Cookies.
you will always get حرف الالف , and so you may need to programatically handle that by removing the first 2 characters from the arabic day name ...
As you can see Anas in my post, I already tried that but couldn't succeed. Any contribution would be grateful.
Based on your reply, I can conclude that the obstacles I encountered are due to limitations in .NET and not lack of knowledge. Lucky me[:P]
Nov 26, 2008 03:42 PM|saedh|LINK
Apparently, my friend Anas is busy or not around to follow up, so here is my request to other beloved members:
I wish to display Day Headers of my Calender using DayNameFormat.FirstLetter. For English, Headers are shown OK (S S M T W T F). Unfortunately, FirstLetter format is not supported in Arabic Calender, so I need a workaround. What I can think of is:
1. Read Day Name (Full/Short).
2. Extract the 3rd character of Day Name.
3. Assign extracted character as the FirstLetter of
4. Assign generated DayNameFormat.FirstLetter as the
DayHeaderFormat of Calender.
As I said, tried replacing first 2 letters of Day Name with whitespace, then used
Trim to get rid of space, and then asked Controller to read first letter of resulted string... It didn't work:
myCalender.DayHeaderFormat = Trim(Replace(DayNameFormat.FirstLetter, "ال", " "))
May be something I missed as the logic sounds fine to me. Could someone assist please?
Many thanx in advance.
Nov 26, 2008 04:44 PM|anas|LINK
Hi Saed and Sorry for late ,
Your problem can be solved if you set the DayNameFormat value to "Shortest" ,
<asp:Calendar ID="Calendar1" DayNameFormat="Shortest"
Nov 26, 2008 07:29 PM|saedh|LINK
Good to see you again[:)]
Well, sorry to disappoint you Anas, but that didn't solve the problem. Already tried all possible combinations.
Shortest and Short both yield the first 4 letters. FirstTwoLetters yields the 'AL'. I can see no alternative but to manually work it out. What do you think?
Nov 27, 2008 03:40 AM|anas|LINK
The "Shortes" mode for the Day Names must work well , I tried it and this is what i get on my local ,
The Test Page was :
<%@ Page Language="VB" AutoEventWireup="false" UICulture="ar-OM" Culture="ar-OM" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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" >
<form id="form1" runat="server">
<asp:Calendar ID="Calendar1" runat="server" DayNameFormat="Shortest"></asp:Calendar>
Nov 29, 2008 02:55 AM|saedh|LINK
Don't know how I missed mentioning that I'm using EO Calender not the default asp Calender. You are right that
Shortest retrieves the first letter of actual Day Name as desired; only when working with asp Calender. After your kind clarification, I addressed the issue to EO. Let's see what they will come up with.
One more thing: Culture setup is dynamically handled through code-behind base on user selection (check original post).
Why not asp Calender? Simply because I found its Appearance control via CSS very limited. So I switched to EO Calender which easily facilitated the look I want:
Thank you for your sincere effort my friend. I shall keep you updated. BTW, I switched the status of this post back to
Nov 29, 2008 03:30 PM|saedh|LINK
Addressing this issue to EO revealed a flow in their Calender, which they promised to rectify. So, until they do:
Would it be possible to store a customed abbreviated day names into an array then use entries of said array as Day Headers of Calender? If yes, could someone show me how?
Many thanks in advance.