Question

i know this is pretty noobish, i am a vb.net developer and need to know why is @T used in NopCommerce and what are its benefits / usage?

e.g we can take the code below for explanation.. i am trying to do @T("Forum.Forums").ToUpper() and it throws an error..

CS1061: 'Nop.Web.Framework.Localization.LocalizedString' does not contain a definition for ...

@model MenuModel  @using Nop.Web.Models.Common;

<ul class="top-menu">
    @Html.Widget("header_menu_before")
    <li><a href="@Url.RouteUrl("HomePage")">@T("HomePage")</a></li>
    @if (Model.RecentlyAddedProductsEnabled)
    {
        <li><a href="@Url.RouteUrl("RecentlyAddedProducts")">@T("Products.NewProducts")</a>
        </li>
    }
    <li><a href="@Url.RouteUrl("ProductSearch")">@T("Search")</a> </li>
    <li><a href="@Url.RouteUrl("CustomerInfo")">@T("Account.MyAccount")</a></li>
    @if (Model.BlogEnabled)
    {
        <li><a href="@Url.RouteUrl("Blog")">@T("Blog")</a></li>
    }
    @if (Model.ForumEnabled)
    {
        <li><a href="@Url.RouteUrl("Boards")">@T("Forum.Forums")</a></li>
    }
    <li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>
    @Html.Widget("header_menu_after") </ul>
Était-ce utile?

La solution

It is used for localization. You can find same pattern in Orchard CMS as well.

NOP Commerce stores resources (key value pairs) used for localization in database. While accessing, it does cache them and uses their engine to access these resources.

@T is just a method to access to resources while using differnt langs in the app.

in order to remove the error i mentioned we neet to use Convert.ToString(T("whatever")).ToUpper() and it will not throw that error again

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top