我已经将项目从.Net Core 2.2升级到.Net Core 3.0。
在尝试解决所有警告和错误之后,我现在尝试为该警告的解决方案提供资金:
'IStringLocalizer.WithCulture(CultureInfo)' is obsolete: 'This method is obsolete.
Use `CurrentCulture` and `CurrentUICulture` instead.'
Run Code Online (Sandbox Code Playgroud)
我正在使用它来更改每个登录用户的网站语言。我有此实现可更改每个用户的网站文化:
public class CultureLocalizer : ICultureLocalizer
{
private readonly IStringLocalizer localizer;
public CultureLocalizer(IStringLocalizerFactory factory)
{
var type = typeof(Resources.PageResources);
var assemblyName = new AssemblyName(type.GetTypeInfo().Assembly.FullName);
localizer = factory.Create("PageResources", assemblyName.Name);
}
// if we have formatted string we can provide arguments
// e.g.: @Localizer.Text("Hello {0}", User.Name)
public LocalizedString Get(string key, params string[] arguments)
{
return arguments == null ? localizer[key] : localizer[key, arguments];
} …Run Code Online (Sandbox Code Playgroud)