Where are the autogen properties in asp.net core localizers?

Two days ago a collegue and I made a review of the brand new asp.net core implementation. We have been pretty exicted about it. Core promises to be

  • more lightweight,
  • well thought through,
  • much faster
  • …and it finally uses dependency injection.

Time to give it a try and leave web api/ asp.net mvc behind.

First review went well, a lot of intransparent configurations had been made obvious. Then I had a look onto the localization implementation. Let’s take the simple sample from the asp.net core documentation:

 

using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Localization;

namespace Localization.StarterWeb.Controllers
{
    [Route("api/[controller]")]
    public class AboutController : Controller
    {
        private readonly IStringLocalizer<AboutController> _localizer;

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

        [HttpGet]
        public string Get()
        {
            return _localizer["About Title"];
        }
   }
}

These things have to be accomplished:

  • IStringLocalizer has to be used with the type of the class specified as generic
  • localizer instance has to be called with a string information

Some thoughts/questions about it:

  • Why is it necessary to have the type of the class defined for that interface? Looks like an IoC necessity to me.
  • Method _localizer[“default text”] is some kind of sub optimal because
    • The defaults actually should also be defined by professional translaters.
    • I don’t want to have magic strings flying around, especially no  string with punctation marks
    • In case that a string couldn’t be found I would like to be informed about it. This is pretty easy when using constant names like “TITLE_ABOUT” or “title_about” if you prefer lowercase names. In this way I can only obtain it when the language is different from default that it stays English.
    • Why do we loose the straight procedure with ResourceManager’s automatic generated code and their properties?

Do I miss anything?

I did ask this question on stack overflow. Not much response up to now, may be due to asp.net core is quite new, I guess?

— UPDATE

Find discussion about the topic in asp.net core localization repo here.