CarType.cs: (枚举)
public enum CarType
{
Sedan,
Hatchback,
Coupe
}
en.json: (本地化文件)
{
"culture": "en",
"texts": {
"Enum:CarType:0": "Sedan Car",
"Enum:CarType:1": "Hatchback Car",
"Enum:CarType:2": "Coupe Car"
}
}
index.js: (javascript用法)
var l = abp.localization.getResource("MyProject");
var localizationKey = "Enum:CarType:" + changeType;
var localized = l(localizationKey);
index.cshtml: (Razor 页面使用情况)
var statuses = (from CarType ct in Enum.GetValues(typeof(ArticleContentSource))
select new {Id = (int)ct, Name=L[$"Enum:ContentSource:{(int)ct }"].Value })
.ToList();
当在 MVC 项目中使用 ABP Tag Helpers 时,它会通过诸如“Enum:EnumName:Value": "localized text"”之类的约定自动本地化
CarCreateModel.cs: (模型)
public class CarCreateModel
{
[Required]
[InputInfoText("Choose car type?")]
public CarType MyCarType { get; set; }
}
index.cshtml: (MVC 页面)
<abp-select asp-for="@Model.CarCreateModel.MyCarType"/>