Page.UICulture - 如何获取的两个字母的UICulture code? [英] Page.UICulture -- How do I retrieve the Two Letter UICulture Code?

查看:281
本文介绍了Page.UICulture - 如何获取的两个字母的UICulture code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET web表单,当设置的的UICulture =EN在@Page指令,一个的Response.Write(Page.UICulture)返回字符串<强>英语,而不是两个字母的语言code EN

In ASP.NET webforms, when setting UICulture="en" in the @Page directive, a Response.Write(Page.UICulture) returns the string "English" instead of the two letter language code "en".

是通过使用此返回两个字母的语言名称的唯一途径?

Is the the only way to return the two letter language name by using this?

CultureInfo.CurrentUICulture.TwoLetterISOLanguageName

还是有更好/更优雅的方式?

Or is there a better / more elegant way?

推荐答案

老实说,我不知道有没有更好的办法来做到这一点。

Honestly I don't know of any better way to do it.

您可以创建一个扩展方法,但可能是矫枉过正:

You could create an extension method, but that might be overkill:

public static class Extensions
{
    public static string GetUICultureCode(this System.Web.UI.Page page)
    {
    	return System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    }
}

然后在你的页面中,您可以访问它的 this.GetUICulture code()

这篇关于Page.UICulture - 如何获取的两个字母的UICulture code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆