在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):AlexTeixeira/Askmethat-Aspnet-JsonLocalizer开源软件地址(OpenSource Url):https://github.com/AlexTeixeira/Askmethat-Aspnet-JsonLocalizer开源编程语言(OpenSource Language):C# 85.4%开源软件介绍(OpenSource Introduction):Askmethat-Aspnet-JsonLocalizerJson Localizer library for .NetStandard and .NetCore Asp.net projects NugetBuildProjectThis library allows users to use JSON files instead of RESX in an ASP.NET application. The code tries to be most compliant with Microsoft guidelines. The library is compatible with NetStandard & NetCore. ConfigurationAn extension method is available for OptionsA set of options is available. You can define them like this : services.AddJsonLocalization(options => {
options.CacheDuration = TimeSpan.FromMinutes(15);
options.ResourcesPath = "mypath";
options.FileEncoding = Encoding.GetEncoding("ISO-8859-1");
options.SupportedCultureInfos = new HashSet<CultureInfo>()
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR")
};
}); Current Options
Search patterns when UseBaseName = trueIf UseBaseName is set to true, it will be searched for lingualization files by the following order - skipping the options below if any option before matches.
PluralizationIn version 2.0.0, Pluralization was introduced. You are now able to manage a singular (left) and plural (right) version for the same Key. PluralSeparator is used as separator between the two strings. For example : User|Users for key Users To use plural string, use parameters from IStringLocalizer, if last parameters is a boolean, pluralization will be activated. Pluralization is available with IStringLocalizer, IViewLocalizer and HtmlStringLocalizer : In version 3.1.1 and above you can have multiple pluralization, to use it, you should
use IJsonStringLocalizer interface and this method localizer.GetString("Users", true); Clean Memory CacheVersion 2.2.0+ allows you to clean cache. It's usefull when you want's tu update in live some translations. Example public class HomeController{
private readonly IJsonStringLocalizer _localizer;
public HomeController(IJsonStringLocalizer<HomeController> localizer)
{
_localizer = localizer;
_localizer.ClearMemCache(new List<CultureInfo>()
{
new CultureInfo("en-US")
});
}
} Blazor Server HTML parsingAs you know, Blazor Server does not provide IHtmlLocalizer. To avoid this, you can now use
from IJsonStringLocalizer this method InformationPlatform Support Version 3.2 and bellow
Version 4 and above
WithCulture method WhithCulture method is not implemented and will not be implemented. ASP.NET Team, start to set this method Obsolete for version 3 and will be removed in version 4 of asp.net core. For more information : #46 Localization modeAs asked on the request #64, Some user want to have the possiblities to manage file with i18n way. To answer this demand, a localization mode was introduced with default value Basic. Basic version means the the one describe in the previous parts I18nTo use the i18n file management, use the the option Localization mode like this : {
"Name": "Name",
"Color": "Color"
} File name File name are important for some purpose (Culture looking, parent culture, fallback). Please use this pattern : [fileName].[culture].json If you need a fallback culture that target all culture, you can create a file named localisation.json. Of course, if this file does not exist, the chosen default culture is the fallback. Important: In this mode, the UseBaseName options should be False. For more information : #64 PerformancesAfter talking with others Devs about my package, they asked my about performance. BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
Intel Core i7-10870H CPU 2.20GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=6.0.101
[Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
DefaultJob : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
Contributors
A special thanks to @Compufreak345 for is hard work. He did a lot for this repo. License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论