Hi I have a question about the SharedResources file. It is glanced over in the tutorial here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization, and I'm not sure if I get it correctly.
我应该创建一个SharedResources.cs
类,但是我应该把它放在哪里,它应该是空的还是需要用一些数据填充它?
资源文件也是一样,我应该创建一个SharedResources.da.resx
文件并将所有共享字符串放在那里吗?它应该go 哪里?
当我使用IHtmlLocalizer<SharedResources>
时,我是否只写@using
并将其指向SharedResources.cs
所在的名称空间?
我try 将SharedResources.cs
和SharedResources.da.resx
放到Resources文件夹中,并使用它将网站语言更改为丹麦语,但不起作用.使用专用资源文件(如Index.da.resx
和IViewLocalizer
)可以正常工作,但IHtmlLocalizer<SharedResources>
似乎不起作用.
当我查看页面底部链接到的示例项目时,我没有找到任何使用SharedResources的地方,如果有人用这样的示例更新它,那就太好了.
我试着这样做:
视图/主页/索引.cshtml:
@using Funkipedia.Resources
@using Microsoft.AspNetCore.Mvc.Localization
@inject IHtmlLocalizer<Shared> SharedLocalizer
...
<p>@SharedLocalizer["Hei"]</p>
...
在Startup.cs中ConfigureServices的顶部:
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
在启动中配置的顶部.反恐精英:
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("nb-NO"),
new CultureInfo("sv-SE"),
new CultureInfo("da-DK")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("nb-NO"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
资源文件夹包含名为Shared.cs
和Shared.da.resx
的空类,该类包含共享字符串.我可能需要把它的名字改成SharedResources.cs
和SharedResources.da.resx
吗?