Custom Razor engine, custom tag, just like @ T (& amp; quot; key & amp; quot;) in nopcommerce to implement multi-Mandarin

Source: Internet
Author: User
Tags nopcommerce

Custom Razor engine, custom tag, just like @ T (& quot; key & quot;) in nopcommerce to implement multi-Mandarin

First, you need an abstract class WebViewPage that inherits the WebViewPage

Example


Namespace Loyalty. MemberPortal. Web. Helpers
{
Public abstract class WebViewPage : System. Web. Mvc. WebViewPage
{

// Delegate. If necessary, an IHtmlString is returned.
Public delegate IHtmlStringLocalizer (string key, string range );


Private Localizer _ localizer;


Public Localizer T
{
Get
{
Return (key, range) =>
{

// This section is logical. Here is the code for implementing localization. With httpruntime cache, you can write your own code.

Var _ cacheManager = new MemoryCacheManager ();
List HomePage = _ cacheManager. Get (range, () =>
{
Var _ mamageLocalization = new ManageLocalization ();
Return _ mamageLocalization. GetHome ();
});


Var languageInstance = HttpContext. Current. Request. Cookies ["languageCode"];
Var languageCode = languageInstance = null? 0: languageInstance. Value. transfer=agecodetoid ();
Var value = homePage. Where (m => m. Key = key & m. LanguageId = languageCode). FirstOrDefault (). Value;
Return new HtmlString (value );
};
}
}


Public override void InitHelpers ()
{
Base. InitHelpers ();
}




Public override string Layout
{
Get
{
Var layout = base. Layout;
Return layout;
}
Set
{
Base. Layout = value;
}
}


}


// Required, which is a required element of WebViewPage
Public abstract class WebViewPage: WebViewPage
{
}
}

The next important step is to add the secondary engine to the web. config file. This web. config is in View, not the one in the project.


// Original, default












Then we can call it in our VIEW.

@ T ("joinnow", "homePage") // The parameter corresponds to the T (a, B) method parameter.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.