2017-01-01 240 views
0

我有兩個資源文件Resource.resxResource.ar.resx 與下面的代碼相同的密鑰,但不同英語和阿拉伯數據在 的文本工作正常顯示在下拉列表中的變化英語和阿拉伯數據同時保存按鈕的文字總是顯示英語不是阿拉伯語多種語言數據

 </tr> 
      <tr> 
     <td><span><%=Resources.Resource.Citations%></span></td> 
     <td> 
      <input runat="server" id="taCitations" type="number" style="width: 600px;" /></td> 
    </tr> 
</table> 
<asp:Button ID="btnSave" runat="server" Text="<%$Resources:Resource, Save%>" CssClass="btn" OnClick="btnSave_Click" /> 

我在母版頁

<asp:DropDownList ID="ddlLang" runat="server" AutoPostBack="true"> 
           <asp:ListItem Text="English" Value="en-US"> 
           <asp:ListItem Text="Arabic" Value="ar-sa" /> 
          </asp:DropDownList> 

一個下拉列表,我的母版頁的工作來改變語言是預渲染

protected void Page_PreRender(object sender, EventArgs e) 
{ 

    if (Request.Form["__EVENTTARGET"] != null && Request.Form["__EVENTTARGET"].Contains("ddlLang")) 
    { 
     //Set the Language. 
     Language = Request.Form[Request.Form["__EVENTTARGET"]]; 

    } 
    if (Language == "en-US") 
    { 
     Body.Attributes["dir"] = "ltr"; 
     tdAppParticulars.Attributes["align"] = "right"; 

    } 
    else 
    { 
     Body.Attributes["dir"] = "rtl"; 
     tdAppParticulars.Attributes["align"] = "left"; 

    } 
    Thread.CurrentThread.CurrentCulture = new CultureInfo(Language); 
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(Language); 
    List<ExtFormInstruction1> lefi = bal.ExtFormInstructionByType("External Reviewers"); 

    formInstructions = new Hashtable(); 
    formIDs = new Hashtable(); 
    string currentItemURL = ""; 
    foreach (ExtFormInstruction1 row in lefi) 
    { 
     string itemURL = row.Page; 
     formInstructions[row.Page] = Language == "ar-sa" ? "" : row.Instruction; 
     formIDs[row.Page] = row.FormID; 
     if (Language == "en-US") 
     { 
      lblPageTitle.Text = row.Title; 
     } 
     else if (Language == "ar-sa") 
     { 
      lblPageTitle.Text = bal.GetFormByPage(row.Page.Replace(".aspx", "Ar.aspx"))[0].Title; 

     } 
    } 

    MakeMenu(Language); 
    if (IsPostBack) 
    { 
     return; 
    } 
    lblApplicantEmail.Text = bal.GetApplicant(ApplicationID)[0].NameString; 
    lblEmployee.Text = erBAL.GetExtRevByID(ExtReviewerID)[0].Name; 
    /* printer friendly */ 
    if (Utils.IsPrintMode()) 
    { 
     tdLeftMenu.Visible = false; 
     lnkPrint.Visible = false; 
    } 
    lnkPrint.NavigateUrl = currentItemURL + "?print=1"; 

} 

語言是在母版頁屬性

public string Language 
{ 
    set 
    { 
     Session["Language"] = value; 
    } 
    get 
    { 
     if (Session["Language"] != null) 
     { 
      return Session["Language"].ToString(); 
     } 
     else 
     { 
      return "en-US"; 
     } 
    } 
} 

enter image description hereenter image description here

The resource files are added in the GlobalResources

+1

問題只是用'按鈕? – Null

+0

是的沒錯! <%$ Resources:Resource,Save%>不支持多語言 – shomaail

+0

Resource.ar.resx沒有'Save'鍵或值嗎?另外,您可能拼錯了鍵或資源文件的語法? – Null

回答

0

我寧願做這樣的:

<asp:Button ID="btnSave" runat="server" meta:resourceKey="SaveButton" CssClass="btn" OnClick="btnSave_Click" /> 

而在Resource.resx文件,條目就會像

Name: SaveButton.Text 
Value: Save 
Name: SaveButton.Tooltip 
Value: Click to Submit 

同樣在Resource.ar.resx文件

Name: SaveButton.Text 
Value: حفظ 
Name: SaveButton.Tooltip 
Value: انقر فوق لتقديم 
+0

儘管我將Resource.resx和Resource.ar.resx文件放在App_LocalResources文件夾中 – shomaail