rmm5t / jquery-timeago

:clock8: The original jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago").
http://timeago.yarp.com
MIT License
3.82k stars 710 forks source link

Multiple locale support #280

Open mahemoff opened 8 years ago

mahemoff commented 8 years ago

Hi, I've made some updates to support multiple locales simultaneously. It uses a data attribute to decide, e.g. can use <time data-locale='en_abbrev' ...> and define a setting like en_abbrevStrings.

Would it be useful?

Gist

U.setupTimeAgo = ->
  $.extend jQuery.timeago.settings.strings,
    strings: '1 minute'
    hour: '1 hour'
    day: '1 day'
    hours: "%d hours"
    month: '1 month'
    year: '1 year'
    inPast: 'seconds'
    seconds: 'seconds'
    minute: '1 minute'
    week: 'week'
    weeks: 'weeks'
    months: 'months'
    months: '%d months'
    years: '%d years'
  jQuery.timeago.settings.en_abbrevStrings = $.extend {}, jQuery.timeago.settings.strings
  $.extend jQuery.timeago.settings.en_abbrevStrings,
    suffixAgo: ''
    hour: '1h'
    day: '1d'
    hours: "%d h"
    month: '1M'
    year: '1y'
    inPast: 'pre'
    seconds: 's'
    minute: '1m'
    days: '%dd'
    week: '1w'
    weeks: '%dw'
    month: '1M'
    months: '%dM'
    years: '%dy'