我有一个多元文化的Web应用程序,但是由于某些原因,某些领域失去了资源。我确实使用CI / CD,有时会手动修复它,而有些则没有。
关于它的怪异之处是,其他属性工作正常,但int(与外键相关的ID属性)的属性除外,这些属性对输入字段具有自定义帮助程序,但我对所有这些属性均使用默认的Html.LabelFor属性具有显示属性,只有那些int属性会失去资源,成为资源:PropertyNameId就像它们在模型类中一样。
显示属性丢失示例(RequiredRemoteSelect和MvcRemote属性是从RequiredAttribute和Attribute类派生的):
[RequiredRemoteSelect]
[Display(Name = "Material", ResourceType = typeof(Resources.Base))]
[MvcRemote("_GetDropDownListMaterial", "Lista")]
public int MaterialId { get; set; }
工作场所
[Required]
[DataType(DataType.Currency)]
[Display(Name = "Amount", ResourceType = typeof(Resources.Base))]
public decimal Amount { get; set; }
这是我改变文化的方式:
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
var desiredCulture = string.Empty;
if (!string.IsNullOrEmpty(Request.Cookies["Culture"]?.Value))
{
desiredCulture = Request.Cookies["Culture"].Value;
}
else if (Request.UserLanguages?.Length > 0)
{
var culture = Request.UserLanguages.FirstOrDefault();
if (CultureHelper.AvailableCultures.Contains(culture))
{
desiredCulture = culture;
}
else
{
var neultral = CultureHelper.GetNeultralCulture(desiredCulture);
if (CultureHelper.AvailableCultures.Contains(neultral))
{
desiredCulture = neultral;
}
}
}
if (string.IsNullOrEmpty(desiredCulture))
{
desiredCulture = CultureHelper.GetDefaultCulture();
}
var cultureInfo = new CultureInfo(desiredCulture);
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
}