From: David ‘Bombe’ Roden Date: Sat, 19 Nov 2016 15:38:29 +0000 (+0100) Subject: Use time text converter to display “last updated” text X-Git-Tag: 0.9.7^2~417 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4cedb9eb2dc06e707223d39651b6f2bc2e18de0b;p=Sone.git Use time text converter to display “last updated” text --- diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index 50fa272..5f4ab0c 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -32,8 +32,7 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.freenet.wot.Trust; -import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage; +import net.pterodactylus.sone.text.TimeTextConverter; import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; @@ -62,6 +61,7 @@ public class SoneAccessor extends ReflectionAccessor { /** The core. */ private final Core core; + private final TimeTextConverter timeTextConverter; /** * Creates a new Sone accessor. @@ -69,8 +69,9 @@ public class SoneAccessor extends ReflectionAccessor { * @param core * The Sone core */ - public SoneAccessor(Core core) { + public SoneAccessor(Core core, TimeTextConverter timeTextConverter) { this.core = core; + this.timeTextConverter = timeTextConverter; } /** @@ -104,7 +105,7 @@ public class SoneAccessor extends ReflectionAccessor { } else if (member.equals("locked")) { return core.isLocked(sone); } else if (member.equals("lastUpdatedText")) { - return GetTimesAjaxPage.getTime((WebInterface) templateContext.get("webInterface"), sone.getTime()); + return timeTextConverter.getTimeText(sone.getTime()).getL10nText(); } else if (member.equals("trust")) { Sone currentSone = (Sone) templateContext.get("currentSone"); if (currentSone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 50d3323..a1352b9 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -103,6 +103,7 @@ import net.pterodactylus.sone.template.UnknownDateFilter; import net.pterodactylus.sone.text.Part; import net.pterodactylus.sone.text.SonePart; import net.pterodactylus.sone.text.SoneTextParser; +import net.pterodactylus.sone.text.TimeTextConverter; import net.pterodactylus.sone.web.ajax.BookmarkAjaxPage; import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage; import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage; @@ -210,6 +211,9 @@ public class WebInterface { private final PostVisibilityFilter postVisibilityFilter; private final ReplyVisibilityFilter replyVisibilityFilter; + private final TimeTextConverter timeTextConverter = new TimeTextConverter(); + private final L10nFilter l10nFilter = new L10nFilter(this); + /** The “new Sone” notification. */ private final ListNotification newSoneNotification; @@ -271,7 +275,7 @@ public class WebInterface { templateContextFactory = new TemplateContextFactory(); templateContextFactory.addAccessor(Object.class, new ReflectionAccessor()); templateContextFactory.addAccessor(Collection.class, new CollectionAccessor()); - templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore())); + templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore(), new TimeTextConverter())); templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore())); templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore())); templateContextFactory.addAccessor(Album.class, new AlbumAccessor()); @@ -740,14 +744,14 @@ public class WebInterface { pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this, timeTextConverter, l10nFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this, timeTextConverter, l10nFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 2ca7c23..7a4c391 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -32,9 +32,10 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.notify.PostVisibilityFilter; -import net.pterodactylus.sone.notify.ReplyVisibilityFilter; +import net.pterodactylus.sone.freenet.L10nFilter; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.sone.text.TimeText; +import net.pterodactylus.sone.text.TimeTextConverter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.notify.Notification; @@ -53,6 +54,8 @@ public class GetStatusAjaxPage extends JsonPage { /** Date formatter. */ private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss"); + private final TimeTextConverter timeTextConverter; + private final L10nFilter l10nFilter; /** * Creates a new “get status” AJAX handler. @@ -60,8 +63,10 @@ public class GetStatusAjaxPage extends JsonPage { * @param webInterface * The Sone web interface */ - public GetStatusAjaxPage(WebInterface webInterface) { + public GetStatusAjaxPage(WebInterface webInterface, TimeTextConverter timeTextConverter, L10nFilter l10nFilter) { super("getStatus.ajax", webInterface); + this.timeTextConverter = timeTextConverter; + this.l10nFilter = l10nFilter; } /** @@ -156,7 +161,8 @@ public class GetStatusAjaxPage extends JsonPage { synchronized (dateFormat) { jsonSone.put("lastUpdated", dateFormat.format(new Date(sone.getTime()))); } - jsonSone.put("lastUpdatedText", GetTimesAjaxPage.getTime(webInterface, sone.getTime()).getText()); + TimeText timeText = timeTextConverter.getTimeText(sone.getTime()); + jsonSone.put("lastUpdatedText", l10nFilter.format(null, timeText.getL10nText(), Collections.emptyMap())); return jsonSone; } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java index 02fd0c1..429a275 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -21,11 +21,15 @@ import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; import java.util.concurrent.TimeUnit; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; +import net.pterodactylus.sone.freenet.L10nFilter; +import net.pterodactylus.sone.text.TimeText; +import net.pterodactylus.sone.text.TimeTextConverter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; @@ -41,6 +45,8 @@ public class GetTimesAjaxPage extends JsonPage { /** Formatter for tooltips. */ private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss"); + private final TimeTextConverter timeTextConverter; + private final L10nFilter l10nFilter; /** * Creates a new get times AJAX page. @@ -48,8 +54,10 @@ public class GetTimesAjaxPage extends JsonPage { * @param webInterface * The Sone web interface */ - public GetTimesAjaxPage(WebInterface webInterface) { + public GetTimesAjaxPage(WebInterface webInterface, TimeTextConverter timeTextConverter, L10nFilter l10nFilter) { super("getTimes.ajax", webInterface); + this.timeTextConverter = timeTextConverter; + this.l10nFilter = l10nFilter; } /** @@ -126,79 +134,8 @@ public class GetTimesAjaxPage extends JsonPage { * @return The formatted age */ private Time getTime(long time) { - return getTime(webInterface, time); - } - - // - // STATIC METHODS - // - - /** - * Returns the formatted relative time for a given time. - * - * @param webInterface - * The Sone web interface (for l10n access) - * @param time - * The time to format the difference from (in milliseconds) - * @return The formatted age - */ - public static Time getTime(WebInterface webInterface, long time) { - if (time == 0) { - return new Time(webInterface.getL10n().getString("View.Sone.Text.UnknownDate"), TimeUnit.HOURS.toMillis(12)); - } - long age = System.currentTimeMillis() - time; - String text; - long refresh; - if (age < 0) { - text = webInterface.getL10n().getString("View.Time.InTheFuture"); - refresh = TimeUnit.MINUTES.toMillis(5); - } else if (age < TimeUnit.SECONDS.toMillis(20)) { - text = webInterface.getL10n().getString("View.Time.AFewSecondsAgo"); - refresh = TimeUnit.SECONDS.toMillis(10); - } else if (age < TimeUnit.SECONDS.toMillis(45)) { - text = webInterface.getL10n().getString("View.Time.HalfAMinuteAgo"); - refresh = TimeUnit.SECONDS.toMillis(20); - } else if (age < TimeUnit.SECONDS.toMillis(90)) { - text = webInterface.getL10n().getString("View.Time.AMinuteAgo"); - refresh = TimeUnit.MINUTES.toMillis(1); - } else if (age < TimeUnit.MINUTES.toMillis(30)) { - text = webInterface.getL10n().getString("View.Time.XMinutesAgo", "min", String.valueOf(TimeUnit.MILLISECONDS.toMinutes(age + TimeUnit.SECONDS.toMillis(30)))); - refresh = TimeUnit.MINUTES.toMillis(1); - } else if (age < TimeUnit.MINUTES.toMillis(45)) { - text = webInterface.getL10n().getString("View.Time.HalfAnHourAgo"); - refresh = TimeUnit.MINUTES.toMillis(10); - } else if (age < TimeUnit.MINUTES.toMillis(90)) { - text = webInterface.getL10n().getString("View.Time.AnHourAgo"); - refresh = TimeUnit.HOURS.toMillis(1); - } else if (age < TimeUnit.HOURS.toMillis(21)) { - text = webInterface.getL10n().getString("View.Time.XHoursAgo", "hour", String.valueOf(TimeUnit.MILLISECONDS.toHours(age + TimeUnit.MINUTES.toMillis(30)))); - refresh = TimeUnit.HOURS.toMillis(1); - } else if (age < TimeUnit.HOURS.toMillis(42)) { - text = webInterface.getL10n().getString("View.Time.ADayAgo"); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(6)) { - text = webInterface.getL10n().getString("View.Time.XDaysAgo", "day", String.valueOf(TimeUnit.MILLISECONDS.toDays(age + TimeUnit.HOURS.toMillis(12)))); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(11)) { - text = webInterface.getL10n().getString("View.Time.AWeekAgo"); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(28)) { - text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / (7 * 24))); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(42)) { - text = webInterface.getL10n().getString("View.Time.AMonthAgo"); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(330)) { - text = webInterface.getL10n().getString("View.Time.XMonthsAgo", "month", String.valueOf((TimeUnit.MILLISECONDS.toDays(age) + 15) / 30)); - refresh = TimeUnit.DAYS.toMillis(1); - } else if (age < TimeUnit.DAYS.toMillis(540)) { - text = webInterface.getL10n().getString("View.Time.AYearAgo"); - refresh = TimeUnit.DAYS.toMillis(7); - } else { - text = webInterface.getL10n().getString("View.Time.XYearsAgo", "year", String.valueOf((long) ((TimeUnit.MILLISECONDS.toDays(age) + 182.64) / 365.28))); - refresh = TimeUnit.DAYS.toMillis(7); - } - return new Time(text, refresh); + TimeText timeText = timeTextConverter.getTimeText(time); + return new Time(l10nFilter.format(null, timeText.getL10nText(), Collections.emptyMap()), timeText.getRefreshTime()); } /** diff --git a/src/main/resources/i18n/sone.de.properties b/src/main/resources/i18n/sone.de.properties index aabcd67..e655691 100644 --- a/src/main/resources/i18n/sone.de.properties +++ b/src/main/resources/i18n/sone.de.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=in der Zukunft View.Time.AFewSecondsAgo=vor ein paar Sekunden View.Time.HalfAMinuteAgo=vor einer halben Minute View.Time.AMinuteAgo=vor ungefähr einer Minute -View.Time.XMinutesAgo=vor ${min} Minuten +View.Time.XMinutesAgo=vor {0} Minuten View.Time.HalfAnHourAgo=vor einer halben Stunde View.Time.AnHourAgo=vor ungefähr einer Stunde -View.Time.XHoursAgo=vor ${hour} Stunden +View.Time.XHoursAgo=vor {0} Stunden View.Time.ADayAgo=vor ungefähr einem Tag -View.Time.XDaysAgo=vor ${day} Tagen +View.Time.XDaysAgo=vor {0} Tagen View.Time.AWeekAgo=vor ungefähr einer Woche -View.Time.XWeeksAgo=vor ${week} Wochen +View.Time.XWeeksAgo=vor {0} Wochen View.Time.AMonthAgo=vor ungefähr einem Monat -View.Time.XMonthsAgo=vor ${month} Monaten +View.Time.XMonthsAgo=vor {0} Monaten View.Time.AYearAgo=vor ungefähr einem Jahr -View.Time.XYearsAgo=vor ${year} Jahren +View.Time.XYearsAgo=vor {0} Jahren WebInterface.DefaultText.StatusUpdate=Was beschäftigt Sie gerade? WebInterface.DefaultText.Message=Schreiben Sie eine Nachricht… diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index f7695a0..7b62cf1 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=in the future View.Time.AFewSecondsAgo=a few seconds ago View.Time.HalfAMinuteAgo=about half a minute ago View.Time.AMinuteAgo=about a minute ago -View.Time.XMinutesAgo=${min} minutes ago +View.Time.XMinutesAgo={0} minutes ago View.Time.HalfAnHourAgo=half an hour ago View.Time.AnHourAgo=about an hour ago -View.Time.XHoursAgo=${hour} hours ago +View.Time.XHoursAgo={0} hours ago View.Time.ADayAgo=about a day ago -View.Time.XDaysAgo=${day} days ago +View.Time.XDaysAgo={0} days ago View.Time.AWeekAgo=about a week ago -View.Time.XWeeksAgo=${week} weeks ago +View.Time.XWeeksAgo={0} weeks ago View.Time.AMonthAgo=about a month ago -View.Time.XMonthsAgo=${month} months ago +View.Time.XMonthsAgo={0} months ago View.Time.AYearAgo=about a year ago -View.Time.XYearsAgo=${year} years ago +View.Time.XYearsAgo={0} years ago WebInterface.DefaultText.StatusUpdate=What’s on your mind? WebInterface.DefaultText.Message=Write a Message… diff --git a/src/main/resources/i18n/sone.es.properties b/src/main/resources/i18n/sone.es.properties index 7649bad..f5072c8 100644 --- a/src/main/resources/i18n/sone.es.properties +++ b/src/main/resources/i18n/sone.es.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=en el futuro View.Time.AFewSecondsAgo=hace unos segundos View.Time.HalfAMinuteAgo=hace medio minuto View.Time.AMinuteAgo=hace un minuto -View.Time.XMinutesAgo=hace ${min} minutos +View.Time.XMinutesAgo=hace {0} minutos View.Time.HalfAnHourAgo=hace media hora View.Time.AnHourAgo=hace una hora -View.Time.XHoursAgo=hace ${hour} horas +View.Time.XHoursAgo=hace {0} horas View.Time.ADayAgo=hace un día -View.Time.XDaysAgo=hace ${day} días +View.Time.XDaysAgo=hace {0} días View.Time.AWeekAgo=hace una semana -View.Time.XWeeksAgo=hace ${week} semanas +View.Time.XWeeksAgo=hace {0} semanas View.Time.AMonthAgo=hace un mes -View.Time.XMonthsAgo=hace ${month} meses +View.Time.XMonthsAgo=hace {0} meses View.Time.AYearAgo=hace un año -View.Time.XYearsAgo=hace ${year} años +View.Time.XYearsAgo=hace {0} años WebInterface.DefaultText.StatusUpdate=Qué estás pensando? WebInterface.DefaultText.Message=Escribir un mensaje… diff --git a/src/main/resources/i18n/sone.fr.properties b/src/main/resources/i18n/sone.fr.properties index 8ec579d..86015d0 100644 --- a/src/main/resources/i18n/sone.fr.properties +++ b/src/main/resources/i18n/sone.fr.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=dans le futur View.Time.AFewSecondsAgo=au cours des dernières secondes passées View.Time.HalfAMinuteAgo=au cours des 30 dernières secondes View.Time.AMinuteAgo=au cours de la dernière minute -View.Time.XMinutesAgo=il y a environs ${min} minutes +View.Time.XMinutesAgo=il y a environs {0} minutes View.Time.HalfAnHourAgo=au cours de la dernière demi heure View.Time.AnHourAgo=il y a environ une heure -View.Time.XHoursAgo=Il y a environ ${hour} heures +View.Time.XHoursAgo=Il y a environ {0} heures View.Time.ADayAgo=il y a environ un jour -View.Time.XDaysAgo=il y a plus ou moins ${day} jours +View.Time.XDaysAgo=il y a plus ou moins {0} jours View.Time.AWeekAgo=il y a environ une semaine -View.Time.XWeeksAgo=au cours des dernières ${week}semaines +View.Time.XWeeksAgo=au cours des dernières {0} semaines View.Time.AMonthAgo=au cours du dernier mois -View.Time.XMonthsAgo=au cours des derniers ${month} mois +View.Time.XMonthsAgo=au cours des derniers {0} mois View.Time.AYearAgo=au cours de la dernière année -View.Time.XYearsAgo=au cours des dernières ${year} années +View.Time.XYearsAgo=au cours des dernières {0} années WebInterface.DefaultText.StatusUpdate=Exprimez-vous WebInterface.DefaultText.Message=Écrire un message... diff --git a/src/main/resources/i18n/sone.ja.properties b/src/main/resources/i18n/sone.ja.properties index c78575f..bf81762 100644 --- a/src/main/resources/i18n/sone.ja.properties +++ b/src/main/resources/i18n/sone.ja.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=今より未来 View.Time.AFewSecondsAgo=およそ数秒前 View.Time.HalfAMinuteAgo=およそ30秒前 View.Time.AMinuteAgo=およそ1分前 -View.Time.XMinutesAgo=${min}分前 +View.Time.XMinutesAgo={0}分前 View.Time.HalfAnHourAgo=30分前 View.Time.AnHourAgo=およそ1時間前 -View.Time.XHoursAgo=${hour}時間前 +View.Time.XHoursAgo={0}時間前 View.Time.ADayAgo=およそ1日前 -View.Time.XDaysAgo=${day}日前 +View.Time.XDaysAgo={0}日前 View.Time.AWeekAgo=およそ1週前 -View.Time.XWeeksAgo=${week}週前 +View.Time.XWeeksAgo={0}週前 View.Time.AMonthAgo=およそ1月前 -View.Time.XMonthsAgo=${month}月前 +View.Time.XMonthsAgo={0}月前 View.Time.AYearAgo=およそ1年前 -View.Time.XYearsAgo=${year}年前 +View.Time.XYearsAgo={0}年前 WebInterface.DefaultText.StatusUpdate=何か投稿しますか? WebInterface.DefaultText.Message=メッセージを書いてください… diff --git a/src/main/resources/i18n/sone.no.properties b/src/main/resources/i18n/sone.no.properties index 59ddcda..5a13696 100644 --- a/src/main/resources/i18n/sone.no.properties +++ b/src/main/resources/i18n/sone.no.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=i framtiden View.Time.AFewSecondsAgo=noen fÃ¥ sekunder siden View.Time.HalfAMinuteAgo=omtrent et halvt minutt siden View.Time.AMinuteAgo=omtrent et minutt siden -View.Time.XMinutesAgo=${min} minutter siden +View.Time.XMinutesAgo={0} minutter siden View.Time.HalfAnHourAgo=en halvtime siden View.Time.AnHourAgo=omtrent en time siden -View.Time.XHoursAgo=${hour} timer siden +View.Time.XHoursAgo={0} timer siden View.Time.ADayAgo=omtrent en dag siden -View.Time.XDaysAgo=${day} dager siden +View.Time.XDaysAgo={0} dager siden View.Time.AWeekAgo=omtrent en uke siden -View.Time.XWeeksAgo=${week} uker siden +View.Time.XWeeksAgo={0} uker siden View.Time.AMonthAgo=omtrent en mÃ¥ned siden -View.Time.XMonthsAgo=${month} mÃ¥neder siden +View.Time.XMonthsAgo={0} mÃ¥neder siden View.Time.AYearAgo=omtrent et Ã¥r siden -View.Time.XYearsAgo=${year} Ã¥r siden +View.Time.XYearsAgo={0} Ã¥r siden WebInterface.DefaultText.StatusUpdate=Hva tenker du pÃ¥? WebInterface.DefaultText.Message=Skriv et innlegg… diff --git a/src/main/resources/i18n/sone.pl.properties b/src/main/resources/i18n/sone.pl.properties index 1e78585..e9e460b 100644 --- a/src/main/resources/i18n/sone.pl.properties +++ b/src/main/resources/i18n/sone.pl.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=potem View.Time.AFewSecondsAgo=kilka sekund temu View.Time.HalfAMinuteAgo=około pół godziny temu View.Time.AMinuteAgo=około minutę temu -View.Time.XMinutesAgo=${min}minut temu +View.Time.XMinutesAgo={0} minut temu View.Time.HalfAnHourAgo=pół godziny temu View.Time.AnHourAgo=około godzinę temu -View.Time.XHoursAgo=${hour} godzin temu +View.Time.XHoursAgo={0} godzin temu View.Time.ADayAgo=około godzinę -View.Time.XDaysAgo=${day} dni temu +View.Time.XDaysAgo={0} dni temu View.Time.AWeekAgo=około tydzień temu -View.Time.XWeeksAgo=${week} tygodni temu +View.Time.XWeeksAgo={0} tygodni temu View.Time.AMonthAgo=około miesiąc temu -View.Time.XMonthsAgo=${month} miesięcy +View.Time.XMonthsAgo={0} miesięcy View.Time.AYearAgo=około rok temu -View.Time.XYearsAgo=${year} lat temu +View.Time.XYearsAgo={0} lat temu WebInterface.DefaultText.StatusUpdate=O czym teraz myślisz? WebInterface.DefaultText.Message=Napisz Wiadomość… diff --git a/src/main/resources/i18n/sone.ru.properties b/src/main/resources/i18n/sone.ru.properties index 8fe8f31..bfc7301 100644 --- a/src/main/resources/i18n/sone.ru.properties +++ b/src/main/resources/i18n/sone.ru.properties @@ -394,18 +394,18 @@ View.Time.InTheFuture=в будущем View.Time.AFewSecondsAgo=несколько секунд назад View.Time.HalfAMinuteAgo=около полминуты назад View.Time.AMinuteAgo=около минуты назад -View.Time.XMinutesAgo=${min} минут назад +View.Time.XMinutesAgo={0} минут назад View.Time.HalfAnHourAgo=полчаса назад View.Time.AnHourAgo=около часа назад -View.Time.XHoursAgo=${hour} часов назад +View.Time.XHoursAgo={0} часов назад View.Time.ADayAgo=около дня назад -View.Time.XDaysAgo=${day} дней назад +View.Time.XDaysAgo={0} дней назад View.Time.AWeekAgo=около недели назад -View.Time.XWeeksAgo=${week} недель назад +View.Time.XWeeksAgo={0} недель назад View.Time.AMonthAgo=около месяца назад -View.Time.XMonthsAgo=${month} месяцев назад +View.Time.XMonthsAgo={0} месяцев назад View.Time.AYearAgo=около года назад -View.Time.XYearsAgo=${year} лет назад +View.Time.XYearsAgo={0} лет назад WebInterface.DefaultText.StatusUpdate=Что у вас на уме? WebInterface.DefaultText.Message=Написать сообщение… diff --git a/src/main/resources/templates/include/viewSone.html b/src/main/resources/templates/include/viewSone.html index 60b8ff7..455d81e 100644 --- a/src/main/resources/templates/include/viewSone.html +++ b/src/main/resources/templates/include/viewSone.html @@ -5,7 +5,7 @@
⬊
⬈
✔
-
<%= View.Sone.Label.LastUpdate|l10n|html> "><%sone.lastUpdatedText|html>
+
<%= View.Sone.Label.LastUpdate|l10n|html> "><%sone.lastUpdatedText|l10n|html>
(<%= View.Sone.Stats.Posts|l10n 0=sone.posts.size>, <%= View.Sone.Stats.Replies|l10n 0=sone.replies.size><%if ! sone.allImages.size|match value==0>, <%= View.Sone.Stats.Images|l10n 0=sone.allImages.size><%/if>)
diff --git a/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt b/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt deleted file mode 100644 index 4c35a9d..0000000 --- a/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.test.deepMock -import net.pterodactylus.sone.test.whenever -import net.pterodactylus.sone.web.WebInterface -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.equalTo -import org.junit.Test -import java.lang.System.currentTimeMillis - -/** - * Unit test for [GetTimesAjaxPage]. - */ -class GetTimesAjaxPageTest { - - private val webInterface = deepMock() - - @Test - fun timestampInTheFutureIsTranslatedCorrectly() { - whenever(webInterface.l10n.getString("View.Time.InTheFuture")).thenReturn("in the future") - val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() + 1000) - assertThat(time.text, equalTo("in the future")) - } - - @Test - fun timestampAFewSecondsAgoIsTranslatedCorrectly() { - whenever(webInterface.l10n.getString("View.Time.AFewSecondsAgo")).thenReturn("a few seconds ago") - val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() - 1000) - assertThat(time.text, equalTo("a few seconds ago")) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt index 2f03dee..0f8ba83 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt @@ -10,11 +10,14 @@ import net.pterodactylus.sone.data.Sone.SoneStatus.downloading import net.pterodactylus.sone.data.Sone.SoneStatus.idle import net.pterodactylus.sone.data.Sone.SoneStatus.inserting import net.pterodactylus.sone.data.Sone.SoneStatus.unknown +import net.pterodactylus.sone.freenet.L10nText import net.pterodactylus.sone.freenet.wot.Identity import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.freenet.wot.Trust import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.text.TimeText +import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.util.template.TemplateContext import org.hamcrest.Matcher import org.hamcrest.MatcherAssert.assertThat @@ -29,7 +32,8 @@ import org.junit.Test class SoneAccessorTest { private val core = mock() - private val accessor = SoneAccessor(core) + private val timeTextConverter = mock() + private val accessor = SoneAccessor(core, timeTextConverter) private val templateContext = mock() private val currentSone = mock() private val currentIdentity = mock() @@ -186,6 +190,13 @@ class SoneAccessorTest { } @Test + fun `accessor returns l10n text for last update time`() { + whenever(sone.time).thenReturn(12345) + whenever(timeTextConverter.getTimeText(12345L)).thenReturn(TimeText(L10nText("l10n.key", listOf(3L)), 23456)) + assertAccessorReturnValue("lastUpdatedText", L10nText("l10n.key", listOf(3L))) + } + + @Test fun `accessor returns null trust if there is no current sone`() { whenever(templateContext["currentSone"]).thenReturn(null) assertAccessorReturnValue("trust", null)