diff --git a/modules/blogging/app/Volo.BloggingTestApp/Startup.cs b/modules/blogging/app/Volo.BloggingTestApp/Startup.cs index fc53298f38..6f79fde6ad 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/Startup.cs +++ b/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(); + + services.Configure(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) diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json index a5499b77a5..d8b69815c7 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json +++ b/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", diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/tr.json b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/tr.json index fbfe898e3e..ff96ea4e62 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/tr.json +++ b/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", diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs similarity index 69% rename from modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs rename to modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs index df738fa83d..10047fcb2b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPage.cs +++ b/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]; } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index cc37c15c89..09ab99a121 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -79,7 +79,7 @@ @(Model.Post.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(Model.Post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(Model.Post.CreationTime) } @@ -262,7 +262,7 @@
@(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(commentWithRepliesDto.Comment.CreationTime)

@commentWithRepliesDto.Comment.Text @@ -342,7 +342,7 @@

@(reply.Writer == null ? "" : reply.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(reply.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(reply.CreationTime)

@reply.Text diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml index 236ac47008..b509c00fc4 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml @@ -69,7 +69,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) @L["WiewsWithCount", post.ReadCount] @*| @@ -130,7 +130,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) } @L["WiewsWithCount", post.ReadCount] @@ -199,7 +199,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) @L["WiewsWithCount", post.ReadCount] @*|