A Run-Time Localization Tool
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This tool allows you to build a localization structure whose content can be changed at run-time.
- Download and install .NET 6
- Add NLocalizator NuGet package to your project
dotnet add package NLocalizator
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"
}
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; }
}
using NLocalizator;
builder.Services.AddLocalizator<DaysLocalizationBook>(options =>
options.AddFolderPath(@"*the_folder_path_that_contains_tr.json_file*")
.AddLanguage("tr"));
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;
}
}
- Make sure the new
*lang-name*.json
file be in the same folder withtr.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
- 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).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
Tolga Çakır - [email protected]
Project Link: https://github.com/adessoTurkey-dotNET/NLocalizator