DefaultResources.nopres.xml question

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 年 前
Hello,
I wanted to add an extra local resource so I can later display it when the logic dictates its requirement.  For example, I added a local resource that I want to display when the Cart total is less then or equal to zero, such that the wording would be appropriate for the number of items or item in the cart.  Right now, the default is always plural.. i.e. "There are {0} in your cart."

I added the extra resource to the DefaultResources.nopres.xml page by copying the existing LocalResource and changing the name and the Value, as posted below:

  <LocaleResource Name="ShoppingCart.Mini.ItemText">
             <Value>There is {0} in your cart.</Value>
  </LocaleResource>
  <LocaleResource Name="ShoppingCart.Mini.ItemsText">
            <Value>There are {0} in your cart.</Value>
  </LocaleResource>


Then, I modified the Default.cshtml page like this:

        <div class="count">
            @if (Model.TotalProducts == 0)
            {
                @T("ShoppingCart.Mini.NoItems")
            }
            else
            {
                @if (Model.TotalProducts > 1)
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.ItemsText").Text, $"<a href=\"{Url.RouteUrl("ShoppingCart")}\">{string.Format(T("ShoppingCart.Mini.Items").Text, Model.TotalProducts)}</a>"))
                }
                else
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.ItemText").Text, $"<a href=\"{Url.RouteUrl("ShoppingCart")}\">{string.Format(T("ShoppingCart.Mini.Item").Text, Model.TotalProducts)}</a>"))
                }
            }
        </div>

I was expecting the proper text to be displayed when the Cart Item is = 1 , however,  I am getting the actual LocalResource Text (exactly):    shoppingcart.mini.itemtext

How do I correct this issue?
4 年 前
The only way that I was able to get this to work was to  create these values in the "LocaleStringResource" database table.  Is there an Admin Area for this need?

webzest wrote:
Hello,
I wanted to add an extra local resource so I can later display it when the logic dictates its requirement.  For example, I added a local resource that I want to display when the Cart total is less then or equal to zero, such that the wording would be appropriate for the number of items or item in the cart.  Right now, the default is always plural.. i.e. "There are {0} in your cart."

I added the extra resource to the DefaultResources.nopres.xml page by copying the existing LocalResource and changing the name and the Value, as posted below:

  <LocaleResource Name="ShoppingCart.Mini.ItemText">
             <Value>There is {0} in your cart.</Value>
  </LocaleResource>
  <LocaleResource Name="ShoppingCart.Mini.ItemsText">
            <Value>There are {0} in your cart.</Value>
  </LocaleResource>


Then, I modified the Default.cshtml page like this:

        <div class="count">
            @if (Model.TotalProducts == 0)
            {
                @T("ShoppingCart.Mini.NoItems")
            }
            else
            {
                @if (Model.TotalProducts > 1)
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.ItemsText").Text, $"<a href=\"{Url.RouteUrl("ShoppingCart")}\">{string.Format(T("ShoppingCart.Mini.Items").Text, Model.TotalProducts)}</a>"))
                }
                else
                {
                    @Html.Raw(string.Format(T("ShoppingCart.Mini.ItemText").Text, $"<a href=\"{Url.RouteUrl("ShoppingCart")}\">{string.Format(T("ShoppingCart.Mini.Item").Text, Model.TotalProducts)}</a>"))
                }
            }
        </div>

I was expecting the proper text to be displayed when the Cart Item is = 1 , however,  I am getting the actual LocalResource Text (exactly):    shoppingcart.mini.itemtext

How do I correct this issue?
4 年 前
Configuration > Languages > Edit
yourwebsite.com/Admin/Language/Edit/1
Then you need to clear the cache to get them to load
4 年 前
You can try by this
string.Format(_localizationService.GetResource("ShoppingCart.Mini.Item"), Model.TotalProducts)

You need to inject ILocalizationService in your view page
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.