3

When my project was using

<TargetFramework>netcoreapp3.1</TargetFramework>

I could get the localization injected in my page constructor:

IStringLocalizer<Strings> _localizer;

public IndexModel(IStringLocalizer<Strings> localizer) {
    _localizer = localizer;
}

but still retrieve an alternative language's collection of strings:

var localizer = _localizer.WithCulture(new CultureInfo(cultureCode));
var translatedStr = localizer[c.Value].ToString();

Being in the process of upgrading to:

<TargetFramework>net6.0</TargetFramework>

The _localizer.WithCulture code shows this error in VS Code:

'IStringLocalizer<Strings>' does not contain a definition for 'WithCulture' and no accessible extension method 'WithCulture' accepting a first argument of type 'IStringLocalizer<Strings>' could be found (are you missing a using directive or an assembly reference?)

What is the dotnet 6 version of this?

If I switch back to netcoreapp3.1 I can clearly see the warning:

'IStringLocalizer.WithCulture(CultureInfo)' is obsolete: 'This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.'

But what are the CurrentCulture and CurrentUICulture it is referring to?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Matt W
  • 11,753
  • 25
  • 118
  • 215
  • Does this answer your question? [.Net Core 3 IStringLocalizer.WithCulture(CultureInfo) is obsolete](https://stackoverflow.com/questions/58316533/net-core-3-istringlocalizer-withculturecultureinfo-is-obsolete) – Guru Stron Jun 23 '22 at 17:20

0 Answers0