In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the example analysis of multi-language support in NopCommerce, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The language supported by the system is classful: Language represents
The corresponding class for multilingual resources is: LocalizedProperty
Select a language to store in the class first: GenericAttribute
Multiple languages can be exported to XML files, and of course export is also supported.
IWorkContext and its entity class WebWorkContext are the current running context; the user's login information and some context settings are stored in this class.
Details include: current user information: CurrentCustomer; current user Cookie; currency; language; type of tax; supplier, etc.
There are several ways to present multilingual resources:
First, in the custom class WebViewPage placed the method: t (), through this method, the web page in the display to get the corresponding language text.
In fact, T is just an agent, which is defined as:
Namespace Nop.Web.Framework.Localization {public delegate LocalizedString Localizer (string text, params object [] args);}
This agent returns a value of type LocalizedString, which inherits the interface IHtmlString to ensure that localized text resources are displayed correctly.
IHtmlString is defined as:
/ / Summary: / / represents a HTML-encoded string that should not be encoded again. Public interface IHtmlString {/ / Summary: / / returns a string encoded by HTML. / returns the result: / / HTML-encoded string. String ToHtmlString ();}
Second, by extending HtmlHelper
Class HtmlExtensions extends the HtmlHelper class
It mainly encapsulates some controls and supports multiple languages.
The method LocalizedEditor encapsulates the TabStrip control of Telerik (that is, the multi-tab control-Tab control). When the system supports multiple languages at the same time, one tab is displayed for each language, of course, only when needed. Interface ILocalizedModel and interface ILocalizedModelLocal are used here. Interface ILocalizedModel is used to indicate that a Model class supports this kind of multi-language display, including multi-language data list Locales. The class that implements interface ILocalizedModelLocal is the data of a specific language. The LocalizedEditor method is implemented to support multiple languages based on the cooperation of these interfaces. The Admin project uses this method, but the Web project does not.
Public static HelperResult LocalizedEditor (this HtmlHelper helper, string name, Func localizedTemplate, Func standardTemplate) where T: ILocalizedModel where TLocalizedModelLocal: ILocalizedModelLocal {return new HelperResult (writer = > {if (helper.ViewData.Model.Locales.Count > 1) {var tabStrip = helper.Telerik (). TabStrip (). Name (name) .Items (x = > {x.Add (). Text ("Standard") .content (standardTemplate (helper.ViewData.Model). ToHtmlString ()) .Selected (true) For (int I = 0; I < helper.ViewData.Model.Locales.Count; iTunes +) {var locale = helper.ViewData.Model.Locales [I]; var language = EngineContext.Current.Resolve (). GetLanguageById (locale.LanguageId); x.Add (). Text (language.Name) .content (localizedTemplate (I). ToHtmlString () .ImageUrl ("~ / Content/images/flags/" + language.FlagImageFileName);}}) .ToHtmlString (); writer.Write (tabStrip);} else {standardTemplate (helper.ViewData.Model) .WriteTo (writer);}});}
The extension method NopLabelFor is another multilingual implementation.
This method mainly implements the description of the attribute name according to the subclass NopResourceDisplayName of the property DisplayNameAttribute. This property is a modification of the Model property to specify the name of the property.
For example, the attribute of class AddNewsCommentModel is specified with the NopResourceDisplayName attribute:
Namespace Nop.Web.Models.News {public partial class AddNewsCommentModel: BaseNopModel {[NopResourceDisplayName ("News.Comments.CommentTitle")] [AllowHtml] public string CommentTitle {get; set;} [NopResourceDisplayName ("News.Comments.CommentText")] [AllowHtml] public string CommentText {get; set;} public bool DisplayCaptcha {get; set;}
The implementation of the extension method NopLabelFor of HtmlHelper is as follows:
Public static MvcHtmlString NopLabelFor (this HtmlHelper helper, Expression expression, bool displayHint = true) {var result = new StringBuilder (); var metadata = ModelMetadata.FromLambda_Expression (expression, helper.ViewData); var hintResource = string.Empty; object value = null; if (metadata.AdditionalValues.TryGetValue ("NopResourceDisplayName", out value)) {var resourceDisplayName = value as NopResourceDisplayName; if (resourceDisplayName! = null & & displayHint) {var langId = EngineContext.Current.Resolve (). WorkingLanguage.Id HintResource = EngineContext.Current.Resolve () .GetResource (resourceDisplayName.ResourceKey + ".Hint", langId); result.Append (helper.Hint (hintResource). ToHtmlString ());}} result.Append (helper.LabelFor (expression, new {title = hintResource}); return MvcHtmlString.Create (result.ToString ());} above is all the content of the article "sample Analysis of multilingual support in NopCommerce". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.