ASP.net C# Localization with drop down selector - no changing the language -
i have implemented next 2 resource files, 1 english language (localstrings) , 1 high german (de-de). when alter drop-down not alter language. no errors raised, not visual studio or firebug. any advice?
<%@ page language="c#" autoeventwireup="false" codefile="default.aspx.cs" inherits="_default" uiculture="auto" culture="auto:de-de" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:label id="label1" runat="server" meta:resourcekey="label1" text="<%$ resources:localstrings, lastname %>"></asp:label> <br /> <br /> <asp:dropdownlist id="dropdownlist1" runat="server"> <asp:listitem value="localstrings">english</asp:listitem> <asp:listitem value="de-de">german</asp:listitem> </asp:dropdownlist> </form> </body> </html>
code-behind
using system; using system.collections.generic; using system.linq; using system.threading; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.globalization; public partial class _default : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected override void initializeculture() { string cult = request.form["dropdownlist1"]; if (cult != null) { string selectedlanguage = cult; uiculture = selectedlanguage; civilization = selectedlanguage; thread.currentthread.currentculture = cultureinfo.createspecificculture(selectedlanguage); thread.currentthread.currentuiculture = new cultureinfo(selectedlanguage); } base.initializeculture(); } }
solved
the format of resource files resourcename.culture.resx
create resource file in app_globalresources folder called main.resx. default civilization ( ie invariant )
then create resource file main.en-us.resx
this resources en-us civilization live, , on.
main.resx main.en.resx main.en-us-resx main.en-au.resx main.fr.resx main.fr-fr.resx etc.
to access webpage utilize syntax
<%$ resources:main, email %>
don't worry around culture, scheme work out. exact match first ( en-us ), work that's cultures parent ( en ), parent's parent ( invariant ).
change name of "main" suit needs
asp.net localization
No comments:
Post a Comment