Dear All, someone asked me the following, and I'm also facing the same problem, please identify if this is a bug or there is a solution, if there is a workaround that means it is bug :0). any way please support us in this:
we're trying to implement globalization in an asp.net 2.0 project. generally it works quite good, but we ran into the following problem:
the master page it's resources don't get updated after a language changed event
the architecture is:
in the masterpage there is a dropdownlist with possible language. If the selected language is changed, the culture of the current thread is changed and an event is raised to the page.
the page it's controls all change in a good way, but the control in the master page don't.
Now the masterpage is like a kind of usercontrol inside the page, so it should get the information from the page, and reload it's controls no?
Have you got any idea what we migth do wrong? is there a lack in this architecture?
This doesn't seem like a bug to me as much as a misunderstanding of the page lifecycle with master pages. By the time code in your "language changed" event is executed, your controls have already been populated so any programmatic change you do to culture
and cultureui at this point is lost. It's sort of a chicken and egg thing. You need to have your controls to know that the language was changed, but you can't change the language after the controls have been populated. The link above gives a workaround
that works, but is a little convoluted, but the way that's shown in the QuickStarts (http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/localization/localization.aspx#langprefs)
seems a little more straightforward.
To summarize what they do in the QuickStart: When language change event is fired, they store the new language preference in Profile, then force a redirect back to the page using Response.Redirect. They have overridden InitializeCulture
in the Page class to check Profile for a preferred language, if it's there, it is used. So, when the user changes languages, the browser actually makes two trips - one to set the new preference via the event, and one to reload the page using the new preference.
How this could be used with Master Pages: Obviously if you're using master pages, you probably don't want to have to overload the InitializeCulture on each and every page. However, the master page is actually a control without an InitializeCulture
override. So, what you could do is subclass Page with maybe a "LocalizedPage" class, override it's InitializeCulture method, then subclass from that in each of your pages. You could have your overridden InitializeCulture method check Profile, Session, Cookies,
or whatever you want to see if there's a user preference. If there is, set your culture and cultureui to it (there's code for that floating around all over the place). In your language change event, you'd just populate the Profile, Session, or whatever and
then force a redirect back to the current page to make the changes visible.
thank you for reply. I have a little bit different problem. In global.asax (Application_BeginRequest) I placed "change culture" script to receive requested culture setting from url (I use UrlRewriting script and just want make any search-engine to be able crawl
my website, my pages looks like "MyPage-en.aspx").... almost evrything works OK - my content pages being localized, but User Controls, Controls in Master Page NOT. Please note, I tracked culture - and its okey. Its changed as requested. But User Controls,
Controls in Master Page IS NOT localized.
Rob,
Thank you very much!!! Your example is really cool. I still have one question - how to localize SiteMap? There is method? Or just by creating separate sitemap for languages?
mosessaur
Contributor
2214 Points
353 Posts
MasterPages Localization/Globalization & resources issue
Mar 11, 2006 10:22 AM|LINK
Dear All, someone asked me the following, and I'm also facing the same problem, please identify if this is a bug or there is a solution, if there is a workaround that means it is bug :0). any way please support us in this:
we're trying to implement globalization in an asp.net 2.0 project. generally it works quite good, but we ran into the following problem:
the master page it's resources don't get updated after a language changed event
the architecture is:
in the masterpage there is a dropdownlist with possible language. If the selected language is changed, the culture of the current thread is changed and an event is raised to the page.
the page it's controls all change in a good way, but the control in the master page don't.
Now the masterpage is like a kind of usercontrol inside the page, so it should get the information from the page, and reload it's controls no?
Have you got any idea what we migth do wrong? is there a lack in this architecture?
Software Engineer
rmprimo
Contributor
3639 Points
738 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 11, 2006 02:38 PM|LINK
Try this.
http://forums.asp.net/1219973/ShowPost.aspx
HTH!
Rob
mosessaur
Contributor
2214 Points
353 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 11, 2006 05:43 PM|LINK
Thanks for the quick response.. Now the Second question to ASP.NET Team.
Is this a Bug or an issue in ASP.NET 2.0? Please confirm this
Software Engineer
aeont.com
Member
20 Points
4 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 22, 2006 12:51 PM|LINK
Salam Mohammed,
I have same problem. Even user controls and web.sitemap have same bug (?) .
I'll be thankful for any info with regards to this issue.
jdcrutchley
Member
252 Points
63 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 22, 2006 05:00 PM|LINK
This doesn't seem like a bug to me as much as a misunderstanding of the page lifecycle with master pages. By the time code in your "language changed" event is executed, your controls have already been populated so any programmatic change you do to culture and cultureui at this point is lost. It's sort of a chicken and egg thing. You need to have your controls to know that the language was changed, but you can't change the language after the controls have been populated. The link above gives a workaround that works, but is a little convoluted, but the way that's shown in the QuickStarts (http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/localization/localization.aspx#langprefs) seems a little more straightforward.
To summarize what they do in the QuickStart: When language change event is fired, they store the new language preference in Profile, then force a redirect back to the page using Response.Redirect. They have overridden InitializeCulture in the Page class to check Profile for a preferred language, if it's there, it is used. So, when the user changes languages, the browser actually makes two trips - one to set the new preference via the event, and one to reload the page using the new preference.
How this could be used with Master Pages: Obviously if you're using master pages, you probably don't want to have to overload the InitializeCulture on each and every page. However, the master page is actually a control without an InitializeCulture override. So, what you could do is subclass Page with maybe a "LocalizedPage" class, override it's InitializeCulture method, then subclass from that in each of your pages. You could have your overridden InitializeCulture method check Profile, Session, Cookies, or whatever you want to see if there's a user preference. If there is, set your culture and cultureui to it (there's code for that floating around all over the place). In your language change event, you'd just populate the Profile, Session, or whatever and then force a redirect back to the current page to make the changes visible.
aeont.com
Member
20 Points
4 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 23, 2006 05:47 AM|LINK
Please advice.
rmprimo
Contributor
3639 Points
738 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 23, 2006 10:31 AM|LINK
Volodymyr,
changing the thread should work with user controls(or its descendant - masterpage). I sent you a working project.
Rob
aeont.com
Member
20 Points
4 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 23, 2006 11:45 AM|LINK
Thank you very much!!! Your example is really cool. I still have one question - how to localize SiteMap? There is method? Or just by creating separate sitemap for languages?
Thank you again :)
rmprimo
Contributor
3639 Points
738 Posts
Re: MasterPages Localization/Globalization & resources issue
Mar 23, 2006 03:25 PM|LINK
Vlad,
this should help:
http://msdn2.microsoft.com/en-US/library/ms178427(VS.80).aspx
Rob
Eclipse_2006
Member
5 Points
1 Post
Re: MasterPages Localization/Globalization & resources issue
Apr 07, 2006 08:26 AM|LINK
Can you post the working solution you sent Volodymyr? I think everyone would appreciate it.
Thanks in advance.
Eclipse