不翻译时出现 DataAnnotation Localization Error
DataAnnotation Localization Error when not translate
我在 ASP.NET 核心 MVC 网站上工作,本地化在 Controller 和 View 中运行良好,但我在 DataAnnotation 本地化方面遇到错误:
我的默认语言是英语,我的资源文件名如下:"Index.fr.resx" .
如果需要法语翻译,则使用其他字符串键为 return (键为英文),
但是对于 DataAnnotation,翻译效果很好,但是当需要英文时,网站会显示错误:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Intranet.Resources.ViewModels.News.Add.resources" was correctly embedded or linked into assembly
但是找到文件是因为翻译有效,并且如果需要英语,对于 Controller 或 View 的本地化,关键字符串是 returned 并且工作正常,有什么想法吗?
Add.fr.resx :
Title => Titre
Add.cs
[Display(Name = nameof(Resources.ViewModels.News.Add.Title), ResourceType = typeof(Resources.ViewModels.News.Add))]
public String Title { get; set; }
Startup.cs
services.AddMvc(
config =>
{
config.Filters.Add<ActionFilter>();
})
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
似乎无法在模型中对显示属性进行本地化,所以我只是在视图中进行了本地化:
placeholder="@Localizer[Html.DisplayNameFor(x => x.Title)]"
我在 ASP.NET 核心 MVC 网站上工作,本地化在 Controller 和 View 中运行良好,但我在 DataAnnotation 本地化方面遇到错误:
我的默认语言是英语,我的资源文件名如下:"Index.fr.resx" .
如果需要法语翻译,则使用其他字符串键为 return (键为英文),
但是对于 DataAnnotation,翻译效果很好,但是当需要英文时,网站会显示错误:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Intranet.Resources.ViewModels.News.Add.resources" was correctly embedded or linked into assembly
但是找到文件是因为翻译有效,并且如果需要英语,对于 Controller 或 View 的本地化,关键字符串是 returned 并且工作正常,有什么想法吗?
Add.fr.resx :
Title => Titre
Add.cs
[Display(Name = nameof(Resources.ViewModels.News.Add.Title), ResourceType = typeof(Resources.ViewModels.News.Add))]
public String Title { get; set; }
Startup.cs
services.AddMvc(
config =>
{
config.Filters.Add<ActionFilter>();
})
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
似乎无法在模型中对显示属性进行本地化,所以我只是在视图中进行了本地化:
placeholder="@Localizer[Html.DisplayNameFor(x => x.Title)]"