jquery-timeago icon indicating copy to clipboard operation
jquery-timeago copied to clipboard

Enable programmatic locale switching

Open lorcan opened this issue 11 years ago • 4 comments
trafficstars

I'd like to be able to switch locales dynamically at client-side if possible. Would it be possible to store the locale settings in hashes, like this (adapted from the fr locale):

// French
jQuery.timeago.settings.strings['fr'] = {
   // environ ~= about, it's optional
   prefixAgo: "il y a",
   prefixFromNow: "d'ici",
   seconds: "moins d'une minute",
   minute: "environ une minute",
   minutes: "environ %d minutes",
   hour: "environ une heure",
   hours: "environ %d heures",
   day: "environ un jour",
   days: "environ %d jours",
   month: "environ un mois",
   months: "environ %d mois",
   year: "un an",
   years: "%d ans"
};

This would enable multiple locales to be pulled in at once and selected by using jQuery.timeago.settings.strings = jQuery.timeago.settings.strings['fr']; rather than by overriding jQuery.timeago.settings.strings by pulling in an additional locale file (which either necessitates an additional HTTP request or some server side locale switching).

I'm happy to put together a PR with tests if there is any demand for this.

lorcan avatar Mar 13 '14 11:03 lorcan

I have a patch over at rails-timeago derived from an older PR (#88) as that was necessary to use with Rails (Ruby web framework) along with converted locale files. Maybe that can help you.

Feel free to use this for a PR.

jgraichen avatar Mar 13 '14 11:03 jgraichen

Thanks @jgraichen, that's exactly what I had in mind! I'll play with this and see if it fits my needs. :-)

lorcan avatar Mar 13 '14 13:03 lorcan

@rmm5t Is there any interest in upstreaming the patch from rails-timeago? It has been running in production for over six years now.

This has been again requested in #280. Newer Rails versions support webpack and npm too, a few users of the Rails plugin actually asked for a npm version of the patched plugin, which I kindly refused and redirected to your package.

I've prepared the changes here and, if you are interested, can open up a PR.

jgraichen avatar Jun 13 '20 17:06 jgraichen

@jgraichen Yes, I'm open to accepting this upstream patch. Please open a PR for review.

Thanks.

rmm5t avatar Jun 21 '20 01:06 rmm5t