I've upgraded a project from .Net Core 2.2 to .Net Core 3.0.
After trying to fix all the warnings and errors I'm now trying to find a solution to this warning:
'IStringLocalizer.WithCulture(CultureInfo)' is obsolete: 'This method is obsolete.
Use `CurrentCulture` and `CurrentUICulture` instead.'
I'm using this to change the website language per the logged-in user. I have this implementation to change the website culture per user:
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];
}
public LocalizedString Get(Enum key, params string[] arguments)
{
return arguments == null ? localizer[key.ToString()] : localizer[key.ToString(), arguments];
}
public LocalizedString Get(CultureInfo culture, string key, params string[] arguments)
{
// This is obsolete
return arguments == null ? localizer.WithCulture(culture)[key] : localizer.WithCulture(culture)[key, arguments];
}
public LocalizedString Get(CultureInfo culture, Enum key, params string[] arguments)
{
// This is obsolete
return arguments == null ? localizer.WithCulture(culture)[key.ToString()] : localizer.WithCulture(culture)[key.ToString(), arguments];
}
}
And this is the dummy class which only holds the .resx
file for the translations:
// dummy class for grouping localization resources
public class PageResources
{
}
I couldn't find anything on the web that refers to how to solve this warning except for this discussion on github that appears to have no solution yet.
Had anyone else stumbled upon this warning and found a solution for it?
ViewLocalizer
so I started from Microsoft's implementation from Github and it still has theWithCulture
method in there so I'm wondering how I should resolve it. – Warenne