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

Support locale/humanize #16

Closed
miguelcobain opened this issue Sep 9, 2014 · 6 comments
Closed

Support locale/humanize #16

miguelcobain opened this issue Sep 9, 2014 · 6 comments

Comments

@miguelcobain
Copy link

Could this plugin support humanize()?
It would be awesome if we could use momentjs i18n support: http://momentjs.com/docs/#/i18n/

Or is it up to us to provide a template that uses i18n?

@miguelcobain miguelcobain changed the title Support locale Support locale/humanize Sep 9, 2014
@jsmreese
Copy link
Owner

Not exactly sure what you mean.

Native moment durations have the humanize method. And humanize(true) which is analogous to the moment.fromNow method.
http://momentjs.com/docs/#/durations/humanize/

If you're using this plugin, you can provide whatever template string you want, in whatever language.

The default template function is not exactly i18n friendly (but you could provide your own).
The use of the decimal point (.) for fractional units output is not configurable.

Are you looking for the already-existing duration humanize method, or complete i18n support from this plugin?

@miguelcobain
Copy link
Author

Thanks for your reply.

Basically, this is my problem: moment/moment#348

I need a precise version of humanize, that's why I used this plugin. Where do you think this fits?

@jsmreese
Copy link
Owner

OK, got it.

I'll take a look at everything. I'm not sure where this fits.
It seems like this plugin handles half of what you need -- would be nice if it played nicely with Moment's existing i18n features.

@jsmreese
Copy link
Owner

Took a look at this today and I have a bunch of questions.

In the current version of my plugin, you could supply a localized format template, and you could customize the format tokens to match what users might expect in their language, e.g. A or a for años in Spanish.

The only thing you can't change is the decimal point separator ., which moment.js doesn't capture in its locale definitions.

I could auto-detect the decimal point separator based on the environment using Number.prototype.toLocaleString (see http://stackoverflow.com/questions/1074660/with-a-browser-how-do-i-know-which-decimal-separator-does-the-client-use) and allow override via a new decimalSeparator option for my plugin.

That would be pretty simple and I think it makes sense.

Do you also want a new addition to the format grammar to be able to write format template strings that automatically reference the moment locale relativeTime strings?

Something along the lines of this:

moment.locale('es');

moment.duration(257.5, "minutes").format("<h>, <m>");
// "4 horas, 17 minutos"

moment.duration(257.5, "minutes").format("<h>, <m>, <s>");
// "4 horas, 17 minutos, 30 segundos"

...except that I just noticed that for locale es, relativeTime.s is 'unos segundos' and not '%d segundos', and this looks to hold true across locales.

Also, it seems like you might sometimes want the output from longDateFormat.LT and longDateFormat.LTS but without the meridiem component.

I'm having trouble coming up with a version of this feature that is simpler/easier/better than either supplying your own localized format template string to my plugin or using the precise-<locale> solution proposed here: moment/moment#348 (comment)

What do you think?

@jsmreese
Copy link
Owner

I've added the decimalSeparator option, so you can now localize the format grammar, the default format template function, and the decimal separator used in the output. You can provide your own localized template as well.

Closing this for now because I can't figure out how to use the moment.js localization strings for duration formatting in this plugin in a way that makes sense.

@yvele
Copy link

yvele commented Feb 18, 2016

Sorry for bumping but any news on this issue (and also moment/moment#348 that have a lot of +1) ?

BTW: HumanizeDuration package works pretty well to humanize duration (with local), but it would be nice to have this feature in moment.

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