1

I stumbled across the entire Microsoft Localization Extensions section the other day. IStringLocalizer/ILocalizedString, all that.

I've already got a hand-rolled approach to localization in my current app (.NET 6, WPF, Prism), but I would gladly convert over to this if appropriate; Because it's much easier for a new developer coming on a project to understand something when there are reams of standard MS documentation about it rather than trying to guess what I had in mind.

But virtually every discussion or example of IStringLocalizer that I can find seems to relates to ASP.NET or at least web apps. The docs all seem to assume you're writing ASP.NET.

So are these extensions meant just for ASP.NET and web apps? Is anyone using this approach outside of web apps? And if so can anyone point me to any examples?

-Joe

Joe
  • 5,394
  • 3
  • 23
  • 54

1 Answers1

0

No, as by docs (2021):

In this article, you will learn how to use the IStringLocalizer and IStringLocalizerFactory implementations. All of the example source code in this article relies on the Microsoft.Extensions.Localization and Microsoft.Extensions.Hosting NuGet packages. For more information on hosting, see .NET Generic Host.

There is no mention of being asp.net specific, although, asp.net applications obviously tend to make use of it as well.

The examples do not use asp.net.

I've used the resx file approach in the early days a lot in WPF applications - although slightly different, I see no reason why it wouldn't work in any regular application.

Stefan
  • 17,448
  • 11
  • 60
  • 79
  • The .resx approach does work. I'm using it. But I've been forced to inject my own custom "Localizer"-like interface down to various modules. This just seemed so much like it – Joe Apr 21 '22 at 17:34
  • That is strange because `services.AddLocalization();` should allow you to fetch the default one through DI. – Stefan Apr 21 '22 at 17:45
  • I'm using Prism with Unity as the DI container – Joe Apr 21 '22 at 17:46
  • 1
    Ah, I misunderstood that part. You should be able to use them side by side or hook them up in a way to resolve the instance. But that is a different question. Here's an question about Prism and Microsoft DI: https://stackoverflow.com/questions/61557894/can-prism-use-net-cores-built-in-dependency-injection – Stefan Apr 21 '22 at 17:50