the site already displaying the correct language based on browser's language preference but I want to add an option to change the language regardless of browser's settings
Another geat article on MVC localization - Probably the best way to do it but again I cant find a way to allow user just to click a link and set prefered language.
So let say I have filter added to each controller
[HandleError]
[SetCulture(CultureStore = SetCultureAttribute.CultureLocation.QueryString, QueryStringParamName = "culture")]
public class HomeController : Controller
{ ... actions ... }
This will set current culture based on session variable but what action will set that variable initially???
What code should I execute when user clicks on links to set the language?
I set the Session in CommandBtn_Click. But first is processed the code in
SetCultureAttribute class and then Session is read. That's why
I did some changes in SetCultureAttribute class in GetCultureCode method. That is my code:
MeByMySelf
Member
3 Points
16 Posts
Change current culture
May 22, 2009 07:21 PM|LINK
Hi,
I am creating bilingual web site (English/French). I have created localized resource files for my strings.
I want to put two links on my Master pages to select current language.
How to do this?
Abdulla.Abde...
Contributor
5538 Points
871 Posts
Re: Change current culture
May 22, 2009 07:47 PM|LINK
you can override the initalizeCutlure to change the page culture .
follow this article..
http://aspalliance.com/821
Abdulla Abdelhaq .NET/SharePoint Team Leader
My Articles
blog
MeByMySelf
Member
3 Points
16 Posts
Re: Change current culture
May 22, 2009 08:19 PM|LINK
Hi Abdula,
Thanks for your reply.
I actually rad that article before. But I am having troubles to implement it with MVC application.
The article (and you) suggests overriding InitializeCulture method based on postback.
protected override void InitializeCulture()
{
string lang =Request["DropDownList1"];
if ((lang != null))
{
if (lang != "")
{
Thread.CurrentThread.CurrentUICulture =new CultureInfo(lang);
Thread.CurrentThread.CurrentCulture =CultureInfo.CreateSpecificCulture
(lang);
}
}
}
I was thinking to create a Controller with SetLanguage action that accept a choosen language as a parameter.
But then I don't know how to refresh the CURRENT view with new settings
Any ideas?
Michael
Abdulla.Abde...
Contributor
5538 Points
871 Posts
Re: Change current culture
May 22, 2009 08:29 PM|LINK
check this
http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Localization.aspx
Abdulla Abdelhaq .NET/SharePoint Team Leader
My Articles
blog
MeByMySelf
Member
3 Points
16 Posts
Re: Change current culture
May 22, 2009 08:30 PM|LINK
And I forgot to mention ...
the site already displaying the correct language based on browser's language preference but I want to add an option to change the language regardless of browser's settings
MeByMySelf
Member
3 Points
16 Posts
Re: Change current culture
May 22, 2009 08:34 PM|LINK
This article is great but it uses only browser settings - I cant find a way to allow user just to click a link and set prefered language :(
slasi.net
Member
135 Points
93 Posts
Re: Change current culture
May 23, 2009 07:38 PM|LINK
I am working on the same issue... when i will find a solution i will update this post
anonymouswri...
Contributor
2340 Points
424 Posts
Re: Change current culture
May 25, 2009 10:50 AM|LINK
http://www.iansuttle.com/blog/post/ASPNET-MVC-Action-Filter-for-Localized-Sites.aspx
this might help.
MeByMySelf
Member
3 Points
16 Posts
Re: Change current culture
May 25, 2009 01:21 PM|LINK
Another geat article on MVC localization - Probably the best way to do it but again I cant find a way to allow user just to click a link and set prefered language.
So let say I have filter added to each controller
[HandleError] [SetCulture(CultureStore = SetCultureAttribute.CultureLocation.QueryString, QueryStringParamName = "culture")] public class HomeController : Controller { ... actions ... }a_sh_a
Member
8 Points
4 Posts
Re: Change current culture
May 25, 2009 01:51 PM|LINK
I have two asp ImageButtons in my Master Page
<
asp:ImageButton class="buttonEnglishClass" ID="deutsch" AlternateText="Deutsch" ImageUrl="/Content/images/flag_d.gif" CommandName="deutsch" OnCommand="CommandBtn_Click" runat="server" />I set the Session in CommandBtn_Click. But first is processed the code in SetCultureAttribute class and then Session is read. That's why I did some changes in SetCultureAttribute class in GetCultureCode method. That is my code:
if (filterContext.RequestContext.HttpContext.Request.Params["buttonEnglishClass"] != null && filterContext.RequestContext.HttpContext.Request.Params["buttonEnglishClass"].ToString() != string.Empty) { cultureCode = "en-US"; } if (filterContext.RequestContext.HttpContext.Request.Params["buttonGermanClass"] != null && filterContext.RequestContext.HttpContext.Request.Params["buttonGermanClass"].ToString() != string.Empty) { cultureCode = "de-DE"; }