Reputation: 39
I am developing an asp.net Website.I have Resource.resx file to translate term of website. every thing is ok and I want to translate text of button to english and persian when I use Text='<%#Resources.Resource.ارسال %>' for text it doesn't work and does not display text on it.
<asp:Button ID="Button1" runat="server" Text='<%#Resources.Resource.ارسال %>' Width="94px" CssClass="btn btn-primary" OnClick="Button1_Click" />
Upvotes: 1
Views: 826
Reputation: 17039
Like this:
<asp:Button ID="Button1" runat="server" Text="<%$ Resources:Resource, Button1 %>" />
InitializeCulture()
method in the code behind and set the culture depending on what type of user is viewing the web application.Like this:
public partial class GlobalizationExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void InitializeCulture()
{
//Get the language that the client prefers from the browser
string preferredLanguage = Request.UserLanguages[0];
//Set the language for the page
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo(preferredLanguage);
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture(preferredLanguage);
}
}
If the above doesn't help you here is a great video on different ways of applying globalization in ASP.NET.
Upvotes: 1