可使用 <b>resourcewriter</b> 类以编程方式创建资源,或使用工具 resgen.exe 创建资源。resgen.exe 可使用简单的“键=值”格式作为输入,或使用 .resx 格式的 xml 文件。 <div class="code"><xmp> ; ; lines beginning with a semicolon can be used for comments. ;
[strings] greeting=welcome ! more=read more ... ... </xmp></div>
<p><acme:tabcontrol runat="server"> <tab name="c#"> thread.currentthread.currentculture = new cultureinfo(request.userlanguages[0]); </tab>
<tab name="vb"> thread.currentthread.currentculture = new cultureinfo(request.userlanguages(0)) </tab>
<tab name="jscript"> thread.currentthread.currentculture = new cultureinfo(request.userlanguages[0]); </tab>
</acme:tabcontrol><p>
若要更改初始语言设置,可使用以不同的方式本地化的客户端,或更改浏览器上的语言设置。 例如,对于 internet explorer 5.x,从菜单中选择<b>工具</b>-><b>internet 选项</b>并单击底部的<b>语言</b>按钮。 在接下来的对话框中,可以添加其他语言,并定义它们的优先级。 为简单起见,示例总是选择第一项。 <p> 页第一次加载后,用户可在下拉列表控件 <b>myuiculture</b> 中选择其他区域性。 如果选定的区域性有效,此值将重写从 <b>userlanguages</b> 获得的设置:
<p><acme:tabcontrol runat="server"> <tab name="c#"> string selectedculture = myuiculture.selecteditem.text; if(! selectedculture.startswith("choose")) { // if another culture was selected, use that instead. thread.currentthread.currentculture = new cultureinfo(selectedculture); thread.currentthread.currentuiculture = new cultureinfo(selectedculture); } </tab>
<tab name="vb"> dim selectedculture as string = myuiculture.selecteditem.text if not(selectedculture.startswith("choose")) then ' if another culture was selected, use that instead. thread.currentthread.currentculture = new cultureinfo(selectedculture) thread.currentthread.currentuiculture = new cultureinfo(selectedculture) end if </tab>
<tab name="jscript"> var selectedculture:string = myuiculture.selecteditem.text; if(! selectedculture.startswith("choose")) { // if another culture was selected, use that instead. thread.currentthread.currentculture = new cultureinfo(selectedculture); thread.currentthread.currentuiculture = new cultureinfo(selectedculture); } </tab>
<tab name="vb"> public sub application_start() application("rm") = new resourcemanager("articles", _ server.mappath("resources") + environment.directoryseparatorchar, _ nothing) end sub </tab>
<tab name="jscript"> public function application_start() : void { application["rm"] = new resourcemanager("articles", server.mappath("resources") + environment.directoryseparatorchar, null); } </tab>
<tab name="vb"> _rm = new resourcemanager("localizedstrings", _ assembly.getexecutingassembly(), _ nothing, _ true ) ... overrides protected sub render (writer as htmltextwriter) text = resourcefactory.rmanager.getstring(text) base.render(writer) end sub </tab>
<tab name="jscript"> _rm = new resourcemanager("localizedstrings", assembly.getexecutingassembly(), null, true ); ... override protected function render(writer:htmltextwriter) : void { text = resourcefactory.rmanager.getstring(text); base.render(writer); } </tab>