Hcf Language 多语言组件,基于Localization实现的多语言组件
"Hcf": {
"Language": {
"Default": "zh-CN",
"Cultures": [ "zh-CN", "en-US" ]
}
}
添加一个类文件如下
例如:LanguageResources.cs
再添加对应语言的资源文件
例如英文:LanguageResources.en-US.resx
例如中文:LanguageResources.zh-CN.resx
ConfigureServices
services.AddPack<LanguagePack>();
Configure
IStringLocalizer<LanguageResources> stringLocalizer = provider.GetService<IStringLocalizer<LanguageResources>>();
string hello = stringLocalizer["Hello"];
ConfigureServices
services.AddPack<AspNetCore.LanguagePack>()
控制器Controller中使用
public HomeController(IStringLocalizer<LanguageResources> stringLocalizer)
{
string value=stringLocalizer["Hello"];
}