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.