Answered by:
Why I need a general resx file for my page?

Question
-
User-1193741727 posted
I have a simple page Default.aspx which has one asp:Literal control named Literal1.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplicationTest.Default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %> <!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"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Literal ID="Literal1" runat="server" Text="Hello" meta:resourcekey="Literal1Resource"></asp:Literal> </div> </form> </body> </html>
I have 3 resx files: 1) Default.aspx.resx file which has Literal1Resource.Text = Hello. 2) Default.aspx.en.resx file which has Literal1Resource.Text = enHello. 3) Default.aspx.fr.resx file which has Literal1Resource.Text = frHello.
In the Default.aspx.cs I override the InitializeCulture method to use the culture stored in the session. If there is no culture stored in session then use en-US as default:
protected override void InitializeCulture() { string culture = null; culture = (string)Session["culture"]; culture = culture == null ? "en-Us" : culture; this.Culture = culture; this.UICulture = culture; System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); base.InitializeCulture(); }
To test it I set the session value in Global.asax.cs file in Session_Start method. It is working perfect. If I set Session["culture"] = "en-US"; then the page will show enHello. If I set Session["culture"] = "fr-FR"; then the page will show frHello.
I feel I dont need the Default.aspx.resx file as I will always use Default.aspx.en.resx or Default.aspx.fr.resx files. So I deleted the Default.aspx.resx file. But now it is not working. It shows Hello when I set Session["culture"] = "en-US"; or Session["culture"] = "fr-FR";
Why it is happening like this? Why I need Default.aspx.resx file when I am not going to use it?
Friday, June 17, 2011 4:43 PM
Answers
-
User-1320437544 posted
Hi 1970us,
Well basicaly the default resource file is used to fills up string resources to pages where you haven't set culture globalization or localization.
Hope it helps.
Please, don't forget to mark as "Answered" if it helps. Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, June 18, 2011 5:46 PM -
User-843484705 posted
This is general feature of localization. when you design a applicaton with multilingual, you need to create all resource file enclude defualt file
like Default.aspx.resx, Default.aspx.en-us etc.
if you want to use English is your default language then create default.aspx.resx with english language. without general file resouce will not work.
heppy reading
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 20, 2011 3:17 AM
All replies
-
User-1320437544 posted
Hi 1970us,
Well basicaly the default resource file is used to fills up string resources to pages where you haven't set culture globalization or localization.
Hope it helps.
Please, don't forget to mark as "Answered" if it helps. Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, June 18, 2011 5:46 PM -
User-843484705 posted
This is general feature of localization. when you design a applicaton with multilingual, you need to create all resource file enclude defualt file
like Default.aspx.resx, Default.aspx.en-us etc.
if you want to use English is your default language then create default.aspx.resx with english language. without general file resouce will not work.
heppy reading
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 20, 2011 3:17 AM