5

There is already 7th beta version of ASP.NET 5, in which they say localization features are done. How can I use localization to write multi-language applications in asp.net 5 mvc 6 with visual studio 2015? Is there any working example project for beta 7 version? I have already searched and found many examples but they no more work because the code has been changed since that. Can I still use .resx files (because visual studio does not auto-generate Designer.cs files any more) or are there any newer or alternative methods they suggest?

GiDar
  • 143
  • 2
  • 5

1 Answers1

7

Beta 7 introduced the localization, so it's really brand new. I wrote a short write up of everything that is new on my blog. There are a lot of things new, so if you need the features, I recommend reading it.

You can in fact still use Resx, but you have to understand that the resolution by default is, that the engine tries to find the resx file that matches the view.

For example, if you have a HomeController, and an action called Locpage, you need to have Views.Home.Locpage.cshtml.en-GB.resx to Support en-GB locale. The best part, however, is that you don't really need a resx file anymore :-). You can just implement your own implementation of IStringLocalizer and IStringLocalizerFactory, and it'll work. You can see the code for this on my blog, above.

If you want a working sample, the best place right now is their GitHub, so this right here: https://github.com/aspnet/Mvc/tree/dev/samples/LocalizationSample.Web.

Nick De Beer
  • 5,232
  • 6
  • 35
  • 50
Anže Vodovnik
  • 2,325
  • 16
  • 25
  • Thank you for your answer, definitely helpful. I have another question: can I share a resource file for all/multiple views? – GiDar Sep 24 '15 at 07:38
  • Hm, out of the box, I don't think so. But you can write your own Factory/Provider that is able to do that - you just build in the fallback you need. – Anže Vodovnik Sep 27 '15 at 08:21
  • @GiDar did you find a solution for using one resource file for multiple/all views? – daniel Nov 09 '15 at 11:18
  • @zoidbergi have not tried anything about it yet, but I guess writing custom provider would be a good choice. – GiDar Nov 14 '15 at 14:41