multilingual data from resource file

1.8k views Asked by At

I have two resource file Resource.resx and Resource.ar.resx with the same keys but different english and arabic data in the following code the text in the is working fine showing english and arabic data with the change in the dropdownlist while the text of the save button always shows English not arabic

       </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" />

I have a dropdownlist in master page

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

and my work to change language is in preRender of the master page

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";

}

the Language is a property in master page

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

There are 1 answers

1
RAK On BEST ANSWER

I would rather do it like this:

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

And in the Resource.resx file, the entries will be like

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

Similarly in Resource.ar.resx file

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