Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable programmatic locale switching #173

Open
lorcan opened this issue Mar 13, 2014 · 4 comments
Open

Enable programmatic locale switching #173

lorcan opened this issue Mar 13, 2014 · 4 comments

Comments

@lorcan
Copy link

lorcan commented Mar 13, 2014

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.

@jgraichen
Copy link
Contributor

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.

@lorcan
Copy link
Author

lorcan commented Mar 13, 2014

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

@jgraichen
Copy link
Contributor

@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.

@rmm5t
Copy link
Owner

rmm5t commented Jun 21, 2020

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

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants