Skip to content

adessoTurkey-dotNET/NLocalizator

Repository files navigation

Contributors Forks Stargazers Issues NuGet MIT License


NLocalizator

A Run-Time Localization Tool
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact

About The Project

This tool allows you to build a localization structure whose content can be changed at run-time.

(back to top)

Built With

.Net

(back to top)

Getting Started

Prerequisites

Installation

  • Add NLocalizator NuGet package to your project
dotnet add package NLocalizator

Usage

Create Language Files

Create *lang-name*.json file in project directory. This file name is in use configuration of the tool.

For example tr.json file:

{
	"Monday" : "Pazartesi",
	"Tuesday" : "Salı",
	"Wednesday" : "Çarşamba",
	"Thursday" : "Perşembe",
	"Friday" : "Cuma",
	"Saturday" : "Cumartesi",
	"Sunday" : "Pazar"
}
Create The LocalizationBook
using NLocalizator;

public class DaysLocalizationBook : ILocalizationBook
{
    public string Monday { get; set; }
    public string Tuesday { get; set; }
    public string Wednesday { get; set; }
    public string Thursday { get; set; }
    public string Friday { get; set; }
    public string Saturday { get; set; }
    public string Sunday { get; set; }
}
Dependency Injection
using NLocalizator;

builder.Services.AddLocalizator<DaysLocalizationBook>(options =>
    options.AddFolderPath(@"*the_folder_path_that_contains_tr.json_file*")
    .AddLanguage("tr"));
Call the Localizator
using NLocalizator;

public class WeatherForecastController : ControllerBase
{
    private readonly Localizator<DaysLocalizationBook> _daysLocalizator;

    public WeatherForecastController(Localizator<DaysLocalizationBook> daysLocalizator)
    {
        _daysLocalizator = daysLocalizator;
    }

    [HttpGet(Name = "GetToday")]
    public string Get()
    {
        var today = _daysLocalizator.GetByName("Monday");

        //or

        today = _daysLocalizator.LocalizationBook.Monday;

        return today;
    }
}
Change The Language
  • Make sure the new *lang-name*.json file be in the same folder with tr.json

de.json file:

{
	"Monday" : "Montag",
	"Tuesday" : "Deinstag",
	"Wednesday" : "Mittwoch",
	"Thursday" : "Donnerstag",
	"Friday" : "Freitag",
	"Saturday" : "Samstag",
	"Sunday" : "Sonntag"
}
  • Create a new post method in the controller
[HttpPost(Name = "SetLanguageToGerman")]
public bool SetLanguageToGerman()
{
    _daysLocalizator.ChangeLanguage("de");
    return true;
}

For more examples, please refer to the Sample Project

(back to top)

Roadmap

  • Add multi language support
  • Add multi LocalizationBook support
  • Add language change support
  • Add examples
  • Add license file
  • Add NuGet package
  • Add Changelog
  • Add structral comments for methods
  • Add tests

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.md for more information.

(back to top)

Contact

LinkedIn

Tolga Çakır - tolgacakirx@gmail.com

Project Link: https://github.com/adessoTurkey-dotNET/NLocalizator

(back to top)