Two days ago a collegue and I made a review of the brand new 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/ 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 core documentation:


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

namespace Localization.StarterWeb.Controllers
    public class AboutController : Controller
        private readonly IStringLocalizer<AboutController> _localizer;

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

        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 core is quite new, I guess?


Find discussion about the topic in core localization repo here.

Where are the autogen properties in core localizers?

Leave a Reply

Your email address will not be published. Required fields are marked *

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.
Seo wordpress plugin by