add some lines to mojoBasePage.cs

This forum is for questions about contributing to the project or proposing features that you would like to develop for the project. 

This thread is closed to new posts. You must sign in to post in the forums.
3/28/2011 5:48:04 AM
Gravatar
Total Posts 23
Ahmed Ali Senior Developer

add some lines to mojoBasePage.cs

hi Joe 

i need to add some lines off code to the mojoBasePage.cs

this will help to work in all mojoportal  skins to make it work fine in LTR and RTL directions

            

 

HtmlControl HTMLControl = Master.FindControl("Html1") as HtmlControl;
            if (HTMLControl != null)
            {
                HTMLControl.Attributes.Remove("dir");
                if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
                {
                    HTMLControl.Attributes.Add("dir", "rtl");

                }
                else
                {
                    HTMLControl.Attributes.Add("dir", "ltr");
                }

            }

this code can be add to the end off OnLoad method

method will be like this

 

 

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (
                (Request.IsAuthenticated)
                && (WebConfigSettings.ForceSingleSessionPerUser)
            )
            {
                ForceSingleSession();
            }

            if ((Request.IsAuthenticated) && WebConfigSettings.EnforcRequirePasswordChanges)
            {
                if (!IsChangePasswordPage)
                {
                    SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                    if ((currentUser != null) && (currentUser.MustChangePwd))
                    {
                        Response.Redirect(SiteRoot + "/Secure/PasswordReset.aspx", true);
                    }
                }

            }

            HtmlControl HTMLControl = Master.FindControl("Html1") as HtmlControl;
            if (HTMLControl != null)
            {
                HTMLControl.Attributes.Remove("dir");
                if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
                {
                    HTMLControl.Attributes.Add("dir", "rtl");

                }
                else
                {
                    HTMLControl.Attributes.Add("dir", "ltr");
                }

            }

        }

 

after that we just need to change the html element in layout.Master for skin that we need it to work fine in RTL and LTR from

 

 

 

<html>

to

 

 

<html id="Html1" runat="server">

 

and with small css conditions on css files we can get skin work fine in RTL and LTR

 

can you help me to add this lines to the project

thanks

 

 

3/28/2011 9:00:33 AM
Gravatar
Total Posts 550

Re: add some lines to mojoBasePage.cs

Hi,

I think converting a skin to RTL not just changing the page direction , we need to customize other stuff like image , backgroung-position. So we should maintain rtl skin as a separated skin with own css classes. This is a good idea that we can convert a ltr skin to rtl skin with easiest way but skins design by 3th parties and we can't enfore they to observe this matter. I maintain a lot of rtl skins on mojoPortal Persian Community that in all of them you can see that I change direction of the body or html to rtl.

Asad,

 

 

3/28/2011 12:53:42 PM
Gravatar
Total Posts 23
Ahmed Ali Senior Developer

Re: add some lines to mojoBasePage.cs

hi Asad,

i know that we need more work on skin css files to get the skin work fine in RTL and LTR.

Change page direction will help us to do conditions on files to make skin work fine in all  directions.


some styles nedd to change float we can do that like this:

 

li.topnavitem { float:left; list-style-type:none;  padding:0 7px; }
html[dir='rtl'] li.topnavitem { float:right; list-style-type:none;  padding:0 7px; }

li.firstnav { float:left; list-style-type:none; padding:0 7px 0 5px; }
html[dir='rtl'] li.firstnav { float:right; list-style-type:none; padding:0 7px 0 5px; }

 

images and backgrounds can by set like this

 

h2.moduletitle {  background:url('images/PostHeaderIcon.png') no-repeat; background-position:left;  padding-left:35px;  }

html[dir='rtl'] h2.moduletitle {  background:url('images/rtl/PostHeaderIcon.png') no-repeat; background-position:right;  padding-right:35px;  }

 

and some styles like

 

text-align:left;

 

can be comment or we can change it to be

 

 

text-align:right;


 

i can do needed changes to artisteer-greenlagoon skin to test it or any skin you need to test my way on it

 

thanks

 

3/28/2011 2:21:02 PM
Gravatar
Total Posts 18439

Re: add some lines to mojoBasePage.cs

I have to admit, my initial reaction to this request was the same as Asad, it seemed like it was not needed since it could be controlled by the skin and most skins are designed for either ltr or rtl but not for both. But now that  I see what you are trying to do it seems like a reasonable request. I have made this change in the repository, but I wrapped it inside a check against a new web.config setting and made it disabled by default, so you will need to add the config setting to user.config to make it work.

<add key="AdaptHtmlDirectionToCulture" value="true"/>

I think it is best to have it disabled by default so that it has no unintended consequences for skins designed only for one direction.

Also, it will only work when using the default culture configuration which changes the thread culture based on the browser language preference. In many cases a specific culture will be enforced for a site by configuration, especially in a multi site installation where child sites are for different languages. So if a specific culture is set for the site it will never vary on the CurrentUICulture and the layout.master file will be the only place to control this, directly on the html element.

Best,

Joe

3/28/2011 4:49:45 PM
Gravatar
Total Posts 23
Ahmed Ali Senior Developer

Re: add some lines to mojoBasePage.cs

hi Joe

Thank you for your interest and your appreciation.
and I will help as much as possible in this wonderful project

Here's another addition also need to review and add them to the same file
They would enable the user to choose a display language through the drop-down menu or links or anything like that.

Where URL is added to a new variable name Lang and value will be Language name (ar-EG, ar , en-US , en, fr,........)

 

url will be like this 

 

 

http://www.mojoportal.com/developers.aspx?NewLang=ar

http://www.mojoportal.com/developers.aspx?NewLang=ar-EG

http://www.mojoportal.com/developers.aspx?NewLang=en

http://www.mojoportal.com/developers.aspx?NewLang=en-US

 

 

and this is my code 

 

      

 

         protected override void InitializeCulture()

        {
           
            if (Session["CurrentLanguageCode"] != null)
            {
                CultureInfo culture = new CultureInfo(Session["CurrentLanguageCode"].ToString());
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }

            if (Request.Params["NewLang"] != null)
            {

                CacheHelper.RemoveAllCacheItems();
                Session.Remove("CurrentLanguageCode");

                string Newculture = Request.Params["NewLang"];
                CultureInfo culture = new CultureInfo(Newculture);
                if (culture != null)
                {
                    if (culture.IsNeutralCulture)
                    {
                        culture = CultureInfo.CreateSpecificCulture(culture.Name);

                    }
                    Thread.CurrentThread.CurrentCulture = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;

                    Session.Add("CurrentLanguageCode", culture.Name);
                    string currentUrl = Request.Url.ToString();
                    string newUrl = currentUrl.Substring(0, currentUrl.LastIndexOf("NewLang") - 1);
                    Response.Redirect(newUrl, false);
                    // Server.Transfer(newUrl);
                }
            }
        }
 

 

 

 

 

and we need to add some lines on CultureHelperHttpModule.cs

 

before 

 

if (WebConfigSettings.UseCultureOverride)

 

we need to add 

          

 CultureInfo siteCulture = SiteUtils.GetDefaultCulture();   // this line need to comment after few lines

 

            if (HttpContext.Current.Request.Params.Get("NewLang") != null)
            {
                string cultureName = "";
                cultureName = SiteUtils.SanitizeSkinParam(HttpContext.Current.Request.Params.Get("NewLang"));
                siteCulture = new CultureInfo(cultureName);
                if (siteCulture.IsNeutralCulture)
                {
                    siteCulture = CultureInfo.CreateSpecificCulture(siteCulture.Name.ToString());
                }

                Thread.CurrentThread.CurrentCulture = siteCulture;
                Thread.CurrentThread.CurrentUICulture = siteCulture;
            }

 

 

and we can comment this line

 

CultureInfo siteCulture = SiteUtils.GetDefaultCulture();

 

that can found after 

 

 

if (WebConfigSettings.UseCultureOverride)

 

 

 

 

 

3/30/2011 1:17:15 PM
Gravatar
Total Posts 23
Ahmed Ali Senior Developer

Change site language control

hi all this is a dropDownList can added any place in skin master page will give site users appality to change site language by select proffered language from list.

 

http://www.smsbox.com/languageControl.zip

 

You must sign in to post in the forums. This thread is closed to new posts.