/js-l10n-timeago

A localised version of the Smart Time Ago javascript library.

Primary LanguageJavaScript

js-l10n-timeago

A version of the Smart Time Ago javascript library, rewritten to work with js-l10n localisation and requirejs. Should also work under nodejs.

Usage

Usage is mostly the same as Smart Time Ago, with the following changes:

Loading

This version is written as a requirejs module: the example directory and the requirejs documentation give more information about how to include it in your program.

Configuration

The option l10nBase (default value timeAgo) is a base prefix for generating string tokens to be passed to js-l10n. E.g. the default token for 'now' is timeAgoNow, and the default token for hours is timeAgoHours. These tokens are then looked up in the strings file for the language you have set in the calling code.

You can pass different values of l10nBase on separate invocations of timeago - for example if you want some strings to be in the form '10 minutes ago', but others in the form '10 minutes'.

The strings in the strings file are in this format:

timeAgoNow = just now

timeAgoMinutes = {[ plural(n) ]}
timeAgoMinutes[zero] = 0 minutes ago
timeAgoMinutes[one] = 1 minute ago
timeAgoMinutes[other] = {{n}} minutes ago

For the format of the plural strings in the strings file, see the example directory and the documentation for webL10n.

For other configuration information, see the original documentation.

Example code

There is some test code in the example directory, which generates time elements with a range of different ages, so you can see the times roll over. There are locale files included for English and German. This is online here.