Reputation: 789
I am developing a multilingual ASP.NET
website using the App_GlobalResources
.
In App_GlobalResources
folder, I added two resource files:
Resource.language.en-US.resx
and Resource.language.fr-FR.resx
.
I also added a web form named About.aspx
.
In this page I added this span:
<span>
<asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Resource.language, aboutFoundation%>" />
</span>
And in code behind:
public partial class About : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
Session["lang"] = "en";
}
}
And last, the BasePage
:
public class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
if (!string.IsNullOrEmpty(Request["lang"]))
{
Session["lang"] = Request["lang"];
}
string lang = Convert.ToString(Session["lang"]);
string culture = string.Empty;
if (lang.ToLower().CompareTo("en") == 0 || string.IsNullOrEmpty(culture))
{
culture = "en-US";
}
if (lang.ToLower().CompareTo("fr") == 0)
{
culture = "fr-FR";
}
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
base.InitializeCulture();
}
}
Now when I run the project, I get the following error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The resource object with key 'aboutFoundation' was not found.
What could be the issue? Thanks in advance.
Upvotes: 4
Views: 9762
Reputation: 39956
You don't have a file named Resource.language
. You have a Resource.language.en-US.resx
and a Resource.language.fr-FR.resx
. So you can either add one more file in your App_GlobalResources
folder named: Resource.language.resx
And it's content should be exactly the same as Resource.language.en-US.resx
or you can rename Resource.language.en-US.resx
to Resource.language.resx
so you would have one Resource.language.resx
that is necessary.
Upvotes: 4