Localized (and properly pluralized) a couple of HtmlHelper extensions (around friendly published datetimes)

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-06-10 11:36:44 -07:00
parent ec61ae3060
commit 39c62e142f
18 changed files with 74 additions and 97 deletions

View File

@@ -2,24 +2,25 @@ using System.Web.Mvc;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Localization;
using Orchard.Mvc.Html; using Orchard.Mvc.Html;
namespace Orchard.Blogs.Extensions { namespace Orchard.Blogs.Extensions {
public static class HtmlHelperExtensions { public static class HtmlHelperExtensions {
public static string PublishedState(this HtmlHelper<BlogPost> htmlHelper) { public static LocalizedString PublishedState(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
return htmlHelper.PublishedState(htmlHelper.ViewData.Model); return htmlHelper.PublishedState(htmlHelper.ViewData.Model, T);
} }
public static string PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost) { public static LocalizedString PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, "Draft"); return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("Draft"));
} }
public static string PublishedWhen(this HtmlHelper<BlogPost> htmlHelper) { public static LocalizedString PublishedWhen(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model); return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model, T);
} }
public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) { public static LocalizedString PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, "as a Draft"); return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("as a Draft"), T);
} }
} }
} }

View File

@@ -1,9 +1,7 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2> <h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div> <div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="content"><% Html.Zone("primary", ":manage :metadata");%></div> <div class="content"><% Html.Zone("primary", ":manage :metadata");%></div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%> <%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
<%@ Import Namespace="Orchard.ContentManagement"%> <%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
@@ -11,15 +10,15 @@
<ul> <ul>
<li><% <li><%
if (Model.Item.HasPublished) { %> if (Model.Item.HasPublished) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /><%: T(" Published")%><% <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /> <%: T("Published")%><%
} }
else { %> else { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /><%: T(" Not Published")%><% <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /> <%: T("Not Published")%><%
} %>&nbsp;&#124;&nbsp; } %>&nbsp;&#124;&nbsp;
</li> </li>
<li><% <li><%
if (Model.Item.HasDraft) { %> if (Model.Item.HasDraft) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%: T("Draft") %>" title="<%: T("The post has a draft") %>" /><%=Html.PublishedState(Model.Item)%><% <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%: T("Draft") %>" title="<%: T("The post has a draft") %>" /><%=Html.PublishedState(Model.Item, T) %><%
} }
else { %> else { %>
<%: T("No draft")%><% <%: T("No draft")%><%
@@ -31,10 +30,10 @@
<%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><% <%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
} }
else if (Model.Item.IsPublished) { %> else if (Model.Item.IsPublished) { %>
<%: T("Published: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value)%><% <%: T("Published: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value, T)) %><%
} }
else { %> else { %>
<%: T("Last modified: ") + Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value) %><% <%: T("Last modified: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value, T)) %><%
} %>&nbsp;&#124;&nbsp; } %>&nbsp;&#124;&nbsp;
</li> </li>
<li><%: T("By {0}", Model.Item.Creator.UserName)%></li> <li><%: T("By {0}", Model.Item.Creator.UserName)%></li>

View File

@@ -2,5 +2,5 @@
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%><% <%@ Import Namespace="Orchard.Blogs.Models"%><%
if (Model.Creator != null) { if (Model.Creator != null) {
%><span class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model)) %> | </span><% %><span class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %> | </span><%
} %> } %>

View File

@@ -3,6 +3,6 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<div class="metadata"><% <div class="metadata"><%
if (Model.Creator != null) { if (Model.Creator != null) {
%><div class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model)) %></div><% %><div class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %></div><%
} %> } %>
</div> </div>

View File

@@ -6,7 +6,7 @@ foreach (var comment in Model) { %>
<div class="comment"> <div class="comment">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span> <span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>
<%-- todo: (heskew) need comment permalink --%> <%-- todo: (heskew) need comment permalink --%>
<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span> <span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
</div> </div>
<div class="text"> <div class="text">
<%-- todo: (heskew) comment text needs processing depending on comment markup style --%> <%-- todo: (heskew) comment text needs processing depending on comment markup style --%>

View File

@@ -1,7 +1,6 @@
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<PagesViewModel>" %> <%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<PagesViewModel>" %>
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%> <%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
<%@ Import Namespace="Orchard.ContentManagement"%> <%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Pages.ViewModels"%><% <%@ Import Namespace="Orchard.Pages.ViewModels"%><%
Html.RegisterStyle("admin.css"); %> Html.RegisterStyle("admin.css"); %>
@@ -45,10 +44,10 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<li><% <li><%
// Published or not // Published or not
if (pageEntry.Page.HasPublished) { %> if (pageEntry.Page.HasPublished) { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /><%: T("Published") %>&nbsp;&#124;&nbsp;<% <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /> <%: T("Published") %>&nbsp;&#124;&nbsp;<%
} }
else { %> else { %>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /><%: T("Not Published")%>&nbsp;&#124;&nbsp;<% <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Pages/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /> <%: T("Not Published")%>&nbsp;&#124;&nbsp;<%
} %> } %>
</li> </li>
<li><% <li><%
@@ -66,10 +65,10 @@ using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.DateTime(pageEntry.Page.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><% <%=Html.DateTime(pageEntry.Page.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
} }
else if (pageEntry.Page.IsPublished) { %> else if (pageEntry.Page.IsPublished) { %>
<%: T("Published: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().VersionPublishedUtc.Value) %><% <%: T("Published: {0}", Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().VersionPublishedUtc.Value, T)) %><%
} }
else { %> else { %>
<%: T("Last modified: ") + Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().ModifiedUtc.Value) %><% <%: T("Last modified: {0}", Html.DateTimeRelative(pageEntry.Page.As<ICommonAspect>().ModifiedUtc.Value, T)) %><%
} %>&nbsp;&#124;&nbsp; } %>&nbsp;&#124;&nbsp;
</li> </li>
<li><%: T("By {0}", pageEntry.Page.Creator.UserName)%></li> <li><%: T("By {0}", pageEntry.Page.Creator.UserName)%></li>

View File

@@ -4,7 +4,7 @@ Html.RegisterStyle("admin.css"); %>
<h1><%=Html.TitleForPage(T("Search Index Management").ToString()) %></h1><% <h1><%=Html.TitleForPage(T("Search Index Management").ToString()) %></h1><%
using (Html.BeginForm("update", "admin", FormMethod.Post, new {area = "Orchard.Search"})) { %> using (Html.BeginForm("update", "admin", FormMethod.Post, new {area = "Orchard.Search"})) { %>
<fieldset> <fieldset>
<p><%=T("The search index was last updated {0}. <button type=\"submit\" title=\"Update the search index.\" class=\"primaryAction\">Update</button>", Html.DateTimeRelative(Model.IndexUpdatedUtc))%></p> <p><%=T("The search index was last updated {0}. <button type=\"submit\" title=\"Update the search index.\" class=\"primaryAction\">Update</button>", Html.DateTimeRelative(Model.IndexUpdatedUtc, T))%></p>
<%=Html.AntiForgeryTokenOrchard() %> <%=Html.AntiForgeryTokenOrchard() %>
</fieldset><% </fieldset><%
} }

View File

@@ -1,12 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %> <%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2> <h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div> <div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="postsummary"> <div class="postsummary">
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
</div> </div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%><%
<% if (Model.Creator != null) {
if (Model.Creator != null) { %><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><% } %>
} %>

View File

@@ -1,12 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %> <%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2> <h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div> <div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="postsummary"> <div class="postsummary">
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
</div> </div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%><%
<% if (Model.Creator != null) {
if (Model.Creator != null) { %><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><% } %>
} %>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><% <ul class="comments"><%
foreach (var comment in Model) { %> foreach (var comment in Model) { %>
<li> <li>
<div class="comment">
<div class="comment"> <p><%: comment.Record.CommentText %></p>
<p><%: comment.Record.CommentText %></p> </div>
</div> <div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
<div class="commentauthor"> </div>
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
</li><% </li><%
} %> } %>
</ul> </ul>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><% <ul class="comments"><%
foreach (var comment in Model) { %> foreach (var comment in Model) { %>
<li> <li>
<div class="comment">
<div class="comment"> <p><%: comment.Record.CommentText %></p>
<p><%: comment.Record.CommentText %></p> </div>
</div> <div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
<div class="commentauthor"> </div>
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
</li><% </li><%
} %> } %>
</ul> </ul>

View File

@@ -1,14 +1,9 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<h3><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h3> <h3><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item)) %></h3>
<div class="meta"><%=Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="postsummary"> <div class="postsummary">
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
</div> </div>

View File

@@ -1,7 +1,6 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%><%
<% if (Model.Creator != null) {
if (Model.Creator != null) { %><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
%><%: T("Posted by {0} {1}", Model.Creator.UserName, "|", Html.PublishedWhen(Model)) %><% } %>
} %>

View File

@@ -3,15 +3,12 @@
<ul class="comments"><% <ul class="comments"><%
foreach (var comment in Model) { %> foreach (var comment in Model) { %>
<li> <li>
<div class="comment">
<div class="comment"> <p><%: comment.Record.CommentText %></p>
<p><%: comment.Record.CommentText %></p> </div>
</div> <div class="commentauthor">
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%></span>
<div class="commentauthor"> </div>
<span class="who"><%=Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%></span>&nbsp;<span>said <%=Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault()), "#")%></span>
</div>
</li><% </li><%
} %> } %>
</ul> </ul>

View File

@@ -7,6 +7,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html; using System.Web.Mvc.Html;
using System.Web.Routing; using System.Web.Routing;
using Orchard.Collections; using Orchard.Collections;
using Orchard.Localization;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
using Orchard.Services; using Orchard.Services;
using Orchard.Settings; using Orchard.Settings;
@@ -178,44 +179,44 @@ namespace Orchard.Mvc.Html {
#region Format Date/Time #region Format Date/Time
public static string DateTimeRelative(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull) { public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull, Localizer T) {
return value.HasValue ? htmlHelper.DateTimeRelative(value.Value) : defaultIfNull; return value.HasValue ? htmlHelper.DateTimeRelative(value.Value, T) : defaultIfNull;
} }
//TODO: (erikpo) This method needs localized //TODO: (erikpo) This method needs localized
public static string DateTimeRelative(this HtmlHelper htmlHelper, DateTime value) { public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime value, Localizer T) {
TimeSpan time = htmlHelper.Resolve<IClock>().UtcNow - value; var time = htmlHelper.Resolve<IClock>().UtcNow - value;
if (time.TotalDays > 7) if (time.TotalDays > 7)
return "on " + htmlHelper.DateTime(value, "MMM d yyyy 'at' h:mm tt"); return htmlHelper.DateTime(value, T("'on' MMM d yyyy 'at' h:mm tt"));
if (time.TotalHours > 24) if (time.TotalHours > 24)
return string.Format("{0} day{1} ago", time.Days, time.Days == 1 ? "" : "s"); return T.Plural("1 day ago", "{0} days ago", time.Days);
if (time.TotalMinutes > 60) if (time.TotalMinutes > 60)
return string.Format("{0} hour{1} ago", time.Hours, time.Hours == 1 ? "" : "s"); return T.Plural("1 hour ago", "{0} hours ago", time.Hours);
if (time.TotalSeconds > 60) if (time.TotalSeconds > 60)
return string.Format("{0} minute{1} ago", time.Minutes, time.Minutes == 1 ? "" : "s"); return T.Plural("1 minute ago", "{0} minutes ago", time.Minutes);
if (time.TotalSeconds > 10) if (time.TotalSeconds > 10)
return string.Format("{0} second{1} ago", time.Seconds, time.Seconds == 1 ? "" : "s"); return T.Plural("1 second ago", "{0} seconds ago", time.Seconds);
return "a moment ago"; return T("a moment ago");
} }
public static string DateTime(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull) { public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull) {
return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull; return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull;
} }
public static string DateTime(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull, string customFormat) { public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull, LocalizedString customFormat) {
return value.HasValue ? htmlHelper.DateTime(value.Value, customFormat) : defaultIfNull; return value.HasValue ? htmlHelper.DateTime(value.Value, customFormat) : defaultIfNull;
} }
public static string DateTime(this HtmlHelper htmlHelper, DateTime value) { public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime value) {
//TODO: (erikpo) This default format should come from a site setting //TODO: (erikpo) This default format should come from a site setting
return htmlHelper.DateTime(value, "MMM d yyyy h:mm tt"); return htmlHelper.DateTime(value, new LocalizedString("MMM d yyyy h:mm tt")); //todo: above comment and get rid of just wrapping this as a localized string
} }
public static string DateTime(this HtmlHelper htmlHelper, DateTime value, string customFormat) { public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime value, LocalizedString customFormat) {
//TODO: (erikpo) In the future, convert this to "local" time before calling ToString //TODO: (erikpo) In the future, convert this to "local" time before calling ToString
return value.ToString(customFormat); return value.ToString(customFormat.Text);
} }
#endregion #endregion