ASP.NET 中的自定义文化信息
我从 CultureInfo 中创建了一个 CustomCulture 类。
这是我的代码:
public class CustomCulture : CultureInfo
{
私有字符串_parent;
私有字符串_name;
私有字符串_描述;
public CustomCulture(string parentCulture, string myCultureName) : base(parentCulture)
{
_parent = parentCulture;
_name = myCultureName;
_description = String.Format("custom culture({0})", _name);
}
public override string Name
{
get
{
return _parent + "-" + _name;
}
}
public override CultureInfo Parent
{
get
{
return new CultureInfo(_parent);
}
}
public override string EnglishName
{
get
{
return _description;
}
}
public override string NativeName
{
get
{
return _description;
}
}
}
public partial class _Default : System.Web.UI.Page
{ 私人 DefCulture.CustomCulture abc = new DefCulture.CustomCulture("en-AU", "abc");
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = abc;
}
....
我想要实现的是,例如,如果我创建一个自定义文化 en-AU-abc, 当前页面可以使用本地资源文件Default.aspx.en-AU-abc.resx,
但我无法让它工作,当前页面总是加载Default.aspx.resx
I created a CustomCulture class form CultureInfo.
Here is my code:
public class CustomCulture : CultureInfo
{
private string _parent;
private string _name;
private string _description;
public CustomCulture(string parentCulture, string myCultureName) : base(parentCulture)
{
_parent = parentCulture;
_name = myCultureName;
_description = String.Format("custom culture({0})", _name);
}
public override string Name
{
get
{
return _parent + "-" + _name;
}
}
public override CultureInfo Parent
{
get
{
return new CultureInfo(_parent);
}
}
public override string EnglishName
{
get
{
return _description;
}
}
public override string NativeName
{
get
{
return _description;
}
}
}
public partial class _Default : System.Web.UI.Page
{
private DefCulture.CustomCulture abc = new DefCulture.CustomCulture("en-AU", "abc");
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = abc;
}
....
What I want to achieve is, for example, if I create a custom culture en-AU-abc,
the current page can use local resource file Default.aspx.en-AU-abc.resx,
but I couldn't get it work, the current page always loads Default.aspx.resx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试安装自定义区域性。 请参阅 Microsoft 区域设置生成器 创建 .msi 并运行它来安装您的自定义区域设置(需要 Vista 或更高版本)。 我可以使用 App_GlobalResources 在 Vista 上运行它。
顺便说一句,具有私人使用扩展的自定义区域设置需要 -x-,例如,
en-AU-x-abc。 请参阅构造语言标签
Try installing the custom culture. See Microsoft Locale Builder to create an .msi and run it to install your custom locale (requires Vista or later). I was able to get it working on Vista with App_GlobalResources.
BTW, custom locales with private-use extensions require -x-, for example,
en-AU-x-abc. See Constructing language tags
pb、Rex M:.NET 不支持但经常需要的两种文化:en-ID、es-US。 我喜欢这一点,因为您没有遇到 .NET 的这种限制,您选择采取居高临下的态度 - 因为很明显,一个人问一个您没有答案的问题一定不知道他们在做什么。 您认为 Microsoft 为什么在 .NET 2.0 中引入 CultureAndRegionInfoBuilder 类?
pb, Rex M: Two cultures not supported by .NET that are very often required: en-ID, es-US. I love that because you haven't encountered this limitation of .NET that you choose to take a condescending attitude - because clearly a person asking a question you don't have an answer for must not know what they're doing. Why do you think Microsoft introduced the CultureAndRegionInfoBuilder class in .NET 2.0?