.NET Core 本地化与类库
当资源文件夹位于 webUI 上时它工作正常。我如何将视图的资源文件存储在类库中。感谢您的帮助
[] []
Program.cs
builder.Services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
builder.Services.AddControllersWithViews()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, option =>
{
option.ResourcesPath = "Resources";
})
.AddDataAnnotationsLocalization()
.AddRazorRuntimeCompilation();
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new(builder.Configuration["DefaultLanguage"]);
CultureInfo[] cultures = new CultureInfo[]
{
new("en-US"),
new("tr-TR"),
new("fr-FR")
};
options.RequestCultureProviders = new List<IRequestCultureProvider>
{
new CookieRequestCultureProvider(),
};
options.SupportedCultures = cultures;
options.SupportedUICultures = cultures;
});
It works fine when the resources folder is on the webUI.how do i store the resources file of my Views in class library . Thanks for help
[]
[]
Program.cs
builder.Services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
builder.Services.AddControllersWithViews()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, option =>
{
option.ResourcesPath = "Resources";
})
.AddDataAnnotationsLocalization()
.AddRazorRuntimeCompilation();
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new(builder.Configuration["DefaultLanguage"]);
CultureInfo[] cultures = new CultureInfo[]
{
new("en-US"),
new("tr-TR"),
new("fr-FR")
};
options.RequestCultureProviders = new List<IRequestCultureProvider>
{
new CookieRequestCultureProvider(),
};
options.SupportedCultures = cultures;
options.SupportedUICultures = cultures;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的工作演示,您可以参考:
ResourceLibrary:
SharedResource.cs ,将其放在项目的根文件夹中,不需要包含任何数据,只需包含类声明即可。
MVC项目,Program.cs
Controller本地化,首先添加对ResourceLibrary的引用。
索引本地化
结果:
Here is my working demo , you could refer to :
ResourceLibrary:
SharedResource.cs , put it in the root folder of project and it does not need to contain any data, just the class declaration.
MVC project , Program.cs
Controller localization,first add reference to ResourceLibrary.
Index localization
result: