受欢迎的博客标签

NopCommerce多语言用到的地方

Published

1、 \src\Presentation\Nop.Web\Validators\Blogs\BlogPostValidator.cs

namespace Nop.Web.Validators.Blogs

{

public partial class BlogPostValidator : BaseNopValidator<BlogPostModel>

{

public BlogPostValidator(ILocalizationService localizationService)

{

RuleFor(x => x.AddNewComment.CommentText).NotEmpty().WithMessage(localizationService.GetResource("Blog.Comments.CommentText.Required")).When(x => x.AddNewComment != null);

}

}

}

 2、\src\Presentation\Nop.Web.Framework\Menu\XmlSiteMap.cs

private static void PopulateNode(SiteMapNode siteMapNode, XmlNode xmlNode)

{

//system name

siteMapNode.SystemName = GetStringValueFromAttribute(xmlNode, "SystemName");

//title

var nopResource = GetStringValueFromAttribute(xmlNode, "nopResource");

var localizationService = EngineContext.ServiceProvider.GetRequiredService<ILocalizationService>(); siteMapNode.Title = localizationService.GetResource(nopResource);

//here sitemap.config title localization

//routes, url

string controllerName = GetStringValueFromAttribute(xmlNode, "controller");

string actionName = GetStringValueFromAttribute(xmlNode, "action");

string url = GetStringValueFromAttribute(xmlNode, "url");

if (!string.IsNullOrEmpty(controllerName) && !string.IsNullOrEmpty(actionName))

{

siteMapNode.ControllerName = controllerName;

siteMapNode.ActionName = actionName;

//apply admin area as described here - http://www.nopcommerce.com/boards/t/20478/broken-menus-in-admin-area-whilst-trying-to-make-a-plugin-admin-page.aspx

siteMapNode.RouteValues = new RouteValueDictionary

{

{ "area", "Admin" }

};

}

else if (!string.IsNullOrEmpty(url))

{

siteMapNode.Url = url;

}

//image URL

siteMapNode.IconClass = GetStringValueFromAttribute(xmlNode, "IconClass");

//permission name

var permissionNames = GetStringValueFromAttribute(xmlNode, "PermissionNames");

if (!string.IsNullOrEmpty(permissionNames)){

var permissionService = EngineContext.ServiceProvider.GetRequiredService<IPermissionService>(); siteMapNode.Visible = permissionNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Any(permissionName => permissionService.Authorize(permissionName.Trim()));

}

else

{

siteMapNode.Visible = true;

}

// Open URL in new tab

var openUrlInNewTabValue = GetStringValueFromAttribute(xmlNode, "OpenUrlInNewTab");

bool booleanResult;

if (!string.IsNullOrWhiteSpace(openUrlInNewTabValue) && bool.TryParse(openUrlInNewTabValue, out booleanResult))

{

siteMapNode.OpenUrlInNewTab = booleanResult;

}

}.