Question

I have to a Resource files for Arabic and Spanish languages containing Error messages,dialog messages and some strings which will be used in the code behind.Now I want to access the related language resource file to read the strings as per the user selected culture.

Can any one help me regarding this ?

No correct solution

OTHER TIPS

In web.config set

<system.web>
<globalization uiCulture="en" />
</system.web>

At very first uiCulture is en.

In ASPX file you may use ddl like following:

<asp:DropDownList ID="cboLanguage" runat="server" CssClass="combobox"
Width="150px" meta:resourcekey="cboLanguageResource1">
<asp:ListItem meta:resourceKey="ListItemLanguageResource1" Text="English" Value="en"></asp:ListItem>
<asp:ListItem meta:resourceKey="ListItemLanguageResource5" Text="French" Value="fr"></asp:ListItem>
<asp:ListItem meta:resourceKey="ListItemLanguageResource4" Text="German" Value="de"></asp:ListItem>    
<asp:ListItem meta:resourceKey="ListItemLanguageResource3" Text="Italian" Value="it"></asp:ListItem>                                                    
<asp:ListItem meta:resourceKey="ListItemLanguageResource2" Text="Portuguese" Value="pt"></asp:ListItem>                                                                                                                                                                        
<asp:ListItem meta:resourceKey="ListItemLanguageResource6" Text="Spanish" Value="es"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnLanguage" runat="server" Text="Update" CssClass="button"
                                                        meta:resourcekey="btnLanguageResource1" OnClick="btnLanguage_Click" />

In Code Behind set the uiCulture at btnLanguage_Click

protected void btnLanguage_Click(object sender, EventArgs e)
    {
        Configuration Config = WebConfigurationManager.OpenWebConfiguration("~");
        GlobalizationSection section = (GlobalizationSection)Config.GetSection("system.web/globalization");
        section.UICulture = cboLanguage.SelectedValue.ToString();
        Config.Save();
        Response.Redirect("Defaults.aspx", false);
    } 

In code behind while showing error messages do this:-

Label1.Text = GetLocalResourceObject("Key").ToString();

In resource file

String | Value
Key | Record has been Saved.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top