Browse Source

Merge pull request #16941 from abpframework/salihozkara/blog

Blog Module : Fix Time Ago
pull/16946/head
Engincan VESKE 3 years ago
committed by GitHub
parent
commit
8f544abd12
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      modules/blogging/app/Volo.BloggingTestApp/Startup.cs
  2. 7
      modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json
  3. 9
      modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/tr.json
  4. 53
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs
  5. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml
  6. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml

17
modules/blogging/app/Volo.BloggingTestApp/Startup.cs

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.Localization;
namespace Volo.BloggingTestApp
{
@ -12,6 +13,22 @@ namespace Volo.BloggingTestApp
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<BloggingTestAppModule>();
services.Configure<AbpLocalizationOptions>(options =>
{
options.Languages.Add(new LanguageInfo("ar", "ar", "العربية", "ae"));
options.Languages.Add(new LanguageInfo("en", "en", "English", "gb"));
options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština", "cz"));
options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish", "fi"));
options.Languages.Add(new LanguageInfo("fr", "fr", "Français", "fr"));
options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak", "sk"));
options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in"));
options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it"));
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe", "tr"));
options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português", "br"));
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文", "cn"));
options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁体中文", "cn"));
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)

7
modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json

@ -19,12 +19,19 @@
"ReplyTo": "Reply To {0}",
"ContinueReading": "Continue Reading",
"DaysAgo": "{0} days ago",
"DayAgo": "{0} day ago",
"YearsAgo": "{0} years ago",
"YearAgo": "{0} year ago",
"MonthsAgo": "{0} months ago",
"MonthAgo": "{0} month ago",
"WeeksAgo": "{0} weeks ago",
"WeekAgo": "{0} week ago",
"MinutesAgo": "{0} minutes ago",
"MinuteAgo": "{0} minute ago",
"SecondsAgo": "{0} seconds ago",
"SecondAgo": "{0} second ago",
"HoursAgo": "{0} hours ago",
"HourAgo": "{0} hour ago",
"Now": "now",
"Content": "Content",
"SeeAll": "See All",

9
modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/tr.json

@ -18,13 +18,20 @@
"Reply": "Yanıtla",
"ReplyTo": "{0}'a cevap ver",
"ContinueReading": "Devamı...",
"DaysAgo": "{0} Gün Önce",
"DaysAgo": "{0} gün önce",
"DayAgo": "{0} gün önce",
"YearsAgo": "{0} yıl önce",
"YearAgo": "{0} yıl önce",
"MonthsAgo": "{0} ay önce",
"MonthAgo": "{0} ay önce",
"WeeksAgo": "{0} hafta önce",
"WeekAgo": "{0} hafta önce",
"MinutesAgo": "{0} dakika önce",
"MinuteAgo": "{0} dakika önce",
"SecondsAgo": "{0} saniye önce",
"SecondAgo": "{0} saniye önce",
"HoursAgo": "{0} saat önce",
"HourAgo": "{0} saat önce",
"Now": "şimdi",
"Content": "İçerik",
"SeeAll": "Hepsini Gör",

53
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs → modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@ -6,6 +7,7 @@ using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Localization;
using Markdig;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
using Volo.Blogging.Localization;
namespace Volo.Blogging.Pages.Blog
@ -96,45 +98,42 @@ namespace Volo.Blogging.Pages.Blog
.Build());
}
public LocalizedHtmlString ConvertDatetimeToTimeAgo(DateTime dt)
public LocalizedHtmlString GetLocalizedTimeAgoText(DateTime dt)
{
var timeDiff = DateTime.Now - dt;
var diffInDays = (int) timeDiff.TotalDays;
if (diffInDays >= 365)
switch (diffInDays)
{
return L["YearsAgo", diffInDays / 365];
}
if (diffInDays >= 30)
{
return L["MonthsAgo", diffInDays / 30];
}
if (diffInDays >= 7)
{
return L["WeeksAgo", diffInDays / 7];
}
if (diffInDays >= 1)
{
return L["DaysAgo", diffInDays];
case >= 365:
return GetLocalizedTextAsSingularOrPlural("YearsAgo", "YearAgo", diffInDays / 365);
case >= 30:
return GetLocalizedTextAsSingularOrPlural("MonthsAgo", "MonthAgo", diffInDays / 30);
case >= 7:
return GetLocalizedTextAsSingularOrPlural("WeeksAgo", "WeekAgo", diffInDays / 7);
case >= 1:
return GetLocalizedTextAsSingularOrPlural("DaysAgo", "DayAgo", diffInDays);
}
var diffInSeconds = (int) timeDiff.TotalSeconds;
if (diffInSeconds >= 3600)
switch (diffInSeconds)
{
return L["HoursAgo", diffInSeconds / 3600];
case >= 3600:
return GetLocalizedTextAsSingularOrPlural("HoursAgo", "HourAgo", diffInSeconds / 3600);
case >= 60:
return GetLocalizedTextAsSingularOrPlural("MinutesAgo", "MinuteAgo", diffInSeconds / 60);
case >= 1:
return GetLocalizedTextAsSingularOrPlural("SecondsAgo", "SecondAgo", diffInSeconds);
default:
return L["Now"];
}
if (diffInSeconds >= 60)
{
return L["MinutesAgo", diffInSeconds / 60];
}
if (diffInSeconds >= 1)
{
return L["SecondsAgo", diffInSeconds];
}
return L["Now"];
}
protected virtual LocalizedHtmlString GetLocalizedTextAsSingularOrPlural(string pluralKey, string singularKey, int value)
{
return value != 1 ? L[pluralKey, value] : L[singularKey, value];
}
}
}

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml

@ -79,7 +79,7 @@
<a href="/Members/@Model.Post.Writer.UserName">
@(Model.Post.Writer.UserName)
</a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(Model.Post.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(Model.Post.CreationTime)</span>
</h5>
}
@ -262,7 +262,7 @@
<div class="media-body">
<h5 class="comment-owner">
@(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName)
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(commentWithRepliesDto.Comment.CreationTime)</span>
</h5>
<p id="@commentWithRepliesDto.Comment.Id">
@commentWithRepliesDto.Comment.Text
@ -342,7 +342,7 @@
<div class="media-body">
<h5 class="comment-owner">
@(reply.Writer == null ? "" : reply.Writer.UserName)
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(reply.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(reply.CreationTime)</span>
</h5>
<p id="@reply.Id">
@reply.Text

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml

@ -69,7 +69,7 @@
<a href="/Members/@post.Writer.UserName">
@post.Writer.UserName
</a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5>
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@*<span class="vs-seperator">|</span>
@ -130,7 +130,7 @@
<a href="/Members/@post.Writer.UserName">
@post.Writer.UserName
</a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5>
}
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@ -199,7 +199,7 @@
<a href="/Members/@post.Writer.UserName">
@post.Writer.UserName
</a>
<span>@BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime)</span>
<span>@BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime)</span>
</h5>
<i class="fa fa-eye"></i> @L["WiewsWithCount", post.ReadCount]
@*<span class="vs-seperator">|</span>

Loading…
Cancel
Save