相关疑难解决方法(0)

.Net Core 3 IStringLocalizer.WithCulture(CultureInfo)已过时

我已经将项目从.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)

c# asp.net-core asp.net-core-3.0

6
推荐指数
1
解决办法
297
查看次数

标签 统计

asp.net-core ×1

asp.net-core-3.0 ×1

c# ×1