TimeAgo texts can be localized with the locale attribute. TimeAgo generates automatically updating fuzzy timestamps (e.g. "4 minutes ago"). Based on jquery-timeago by Ryan McGeary.
Register the strings of a locale in PrimeFacesExt.locales.TimeAgo and select it with locale. The locale is applied to the whole jquery-timeago plugin, which is why this example is on its own page.
You've opened this page .
PrimeFaces Extensions was first released .
<div class="card">
<h5>Localized</h5>
<p>Register the strings of a locale in <code>PrimeFacesExt.locales.TimeAgo</code> and select it with <code>locale</code>. The locale is applied to the whole jquery-timeago plugin, which is why this example is on its own page.</p>
<script>
PrimeFacesExt.locales.TimeAgo['nl'] = {
prefixAgo: null,
prefixFromNow: "over",
suffixAgo: "geleden",
suffixFromNow: null,
seconds: "minder dan een minuut",
minute: "ongeveer een minuut",
minutes: "%d minuten",
hour: "ongeveer een uur",
hours: "ongeveer %d uur",
day: "een dag",
days: "%d dagen",
month: "ongeveer een maand",
months: "%d maanden",
year: "ongeveer een jaar",
years: "%d jaar",
wordSeparator: " ",
numbers: []
}
</script>
<p>
You've opened this page
<pe:timeAgo value="#{basicTimeAgoController.created}"
locale="nl" style="font-weight:bold"/>.
</p>
<p>
PrimeFaces Extensions was first released
<pe:timeAgo value="#{basicTimeAgoController.firstRelease}"
locale="nl" style="font-weight:bold"/>.
</p>
</div>
package org.primefaces.extensions.showcase.controller.timeago;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
/**
* @author Jasper de Vries <[email protected]>
*/
@Named
@ViewScoped
public class BasicTimeAgoController implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private final OffsetDateTime created = OffsetDateTime.now();
private final LocalDateTime firstRelease = LocalDate.of(2012, Month.JANUARY, 23).atStartOfDay();
private final LocalDateTime nextMonth = LocalDateTime.now()
.plusMonths(1)
.withDayOfMonth(1)
.truncatedTo(ChronoUnit.DAYS);
public OffsetDateTime getCreated() {
return created;
}
public LocalDateTime getFirstRelease() {
return firstRelease;
}
public LocalDateTime getNextMonth() {
return nextMonth;
}
}