Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have written that code in my blog:

C#
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@model BlogStory
@{
    var word_count = @Model.Body; // Get all content of the story
    var counts = word_count.Count(ch => ch == ' ') + 1;
    var minutes = counts / 200; // Calculate Minutes
    var seconds = counts % 200 / (200 / 60); // Calculate Seconds
    var str_minutes = (minutes == 1) ? Localizer["minute"].ToString() : Localizer["minutes"].ToString();
    var str_seconds = (seconds == 1) ? Localizer["second"].ToString() : Localizer["seconds"].ToString();
}
<div class="card card-body post-card">
    <div class="post-preview">
        <h3 itemprop="headline" class="post-title"><a href="/@Model.Slug">@Model.Title</a></h3>
        <p class="post-meta">
            class="fas fa-calendar"> Sascha Manns
            ^__i class="fas fa-comments"> <span class="disqus-comment-count" data-disqus-identifier="@Model.UniqueId">@Localizer["comments"]</span>.
            class="fas fa-clock"> @minutes @str_minutes  @seconds @str_seconds
            <br />
            ^__i class="fas fa-tags">
            @foreach (var tag in Model.Categories.Split(','))
            {
                <a asp-controller="Tag" asp-action="Index" asp-route-tag="@tag" asp-route-page="">@tag</a>
            }
        </p>
        @Html.Raw(Model.GetSummary())
    </div>
</div>


In runtime i'm getting:
0 Microsoft.AspNetCore.Mvc.Localization.LocalizedHtmlString
30 Microsoft.AspNetCore.Mvc.Localization.LocalizedHtmlString

It should:
0 minutes
30 seconds

What I have tried:

I also tried Localizer["minute"] without ".ToString()" but that gives an error.

All changes i made for localizing are visible there: How do I localize a data provider[^]
Posted
Updated 2-Nov-20 20:28pm
v3

1 solution

The solution i found is the usage of the "Value". So i used it so:
Localizer["minutes"].Value

That one works perfectly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900