Skip to content
A simplification of the configuration of location in .net core
C# CSS JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


A simplification of the configuration of location in .net core


  • Net core 1.0
  • Net core 1.1
  • Net core 2.


PM> Install-Package JCTools.I18N


For configure the localization and globalization settings follow the next steps:

  1. Add the nuget package
PM> Install-Package JCTools.I18N
  1. Add a new private field at the Startup class
private readonly IHostingEnvironment _enviroment;
  1. Set the value of the created field in the last step, with the value of the constructor argument
public Startup(IHostingEnvironment env)
    // Store the enviroment instance
    _enviroment = env;
  1. Create a new empty class. The application will use this class how reference to the unique resources file. (You can use the Startup class)
  2. Create a new folder for stored the resource files, and add a new resource file named equals that the class of the previous step, this resource file not should have the culture postfix. This file will use for get the localized strings for the default culture. This file should have your access modifier setted to Public.
  3. Create the necessary resource files for stored the localized strings of the rest of supported cultures. This files should have your access modifier setted to public.
  4. Add the next lines to the startup class in the ConfugureServices method:
public void ConfigureServices(IServiceCollection services)

        // The supported cultures
        new List<CultureInfo>
                new CultureInfo("en"),
                new CultureInfo("en-US"),
                new CultureInfo("es"),
                new CultureInfo("es-MX")
        // the default culture
        defaultCulture: "es-MX"
    .AddSingleLocalizationFile<I18N, Resources.I18N>(_enviroment);
  1. Add the next line in the method Configure of the Startup class:

   The previous line should will be add before the next code:


app.UseMvc(routes =>
		name: "default",
		template: "{controller=Home}/{action=Index}/{id?}");

For access at the localized strings into the Controllers, use:

  1. Add a private field for stored the localizer instance
private readonly SingleLocalizer _localizer;
  1. Add at the constructor of your controller an argument for receive the localizer instance through dependency injection and set the value of the created field in the previous step
public HomeController(SingleLocalizer localizer)
            // store the receive argument into our field
            _localizer = localizer;
  1. Use the field as shown below:
ViewData["Message"] = _localizer["About_Message"];

For access at the localized string into the views, use:

  1. Add at your _ViewImports.cshtml file the next dependency, it allows access in all views at the Localizer instance:
@inject JCTools.I18N.Services.SingleHtmlLocalizer Localizer
  1. Use the Localize instance as shown below:
<strong>@Localizer["Support"]:</strong> <a href=""></a>

For access to the localized strings into the models and viewmodels, use the data annotation of the namespace System.ComponentModel.DataAnnotations, how to shown below

using System.ComponentModel.DataAnnotations;

namespace JCTools.I18N.Test.ViewModels
    public class ContactViewModel
        [Display(Name = "ContactViewModel_Email", ResourceType = typeof(Resources.I18N))]
        [EmailAddress(ErrorMessageResourceName = "ContactViewModel_EmailError", ErrorMessageResourceType = typeof(Resources.I18N))]
        public string Email { get; set; }
        [Display(Name = "ContactViewModel_Message", ResourceType = typeof(Resources.I18N))]
        public string Message { get; set; }

For view spanish usage process, visit:


MIT License

You can’t perform that action at this time.