问题描述
我创建了一个多语言和多层.net核心项目。我已经使用全球化和本地化来制作多语言项目。数据层,资源和Web项目是相互独立的。当资源文件夹位于主层时,我知道如何实现全球化。
启动:
services.AddLocalization(opt => { opt.ResourcesPath = "Resources"; });
services.AddLocalization();
services.AddMvc().AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization(
options =>
{
options.DataAnnotationLocalizerProvider = (type,factory) =>
{
var assemblyName = new AssemblyName(typeof(SharedResource).GetTypeInfo().Assembly.FullName);
return factory.Create("SharedResource",assemblyName.Name);
};
});
services.Configure<RequestLocalizationoptions>(
opt =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("fa"),new CultureInfo("en")
};
opt.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("fa");
opt.SupportedCultures = supportedCultures;
opt.SupportedUICultures = supportedCultures;
});
services.AddControllersWithViews()
.AddRazorRuntimeCompilation();
我在资源层和资源文件夹中创建了文件,例如在共享文件夹中的布局,如下所示:
_Layout.en-US.resx和
_Layout.fa-IR.resx
但是当我运行项目时,“布局”中没有“资源”。如何在其他层中将资源用于模型和视图?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)