EvanHahn / HumanizeDuration.js

361000 becomes "6 minutes, 1 second"
https://evanhahn.github.io/HumanizeDuration.js/
The Unlicense
1.64k stars 175 forks source link

Feature Request: Option for automatic localized conjunction #117

Closed menthol closed 7 years ago

menthol commented 7 years ago

For now, we have to localize conjunction rules outside of your project. Will be nice if we can have a simple option to turn on localized conjunction. ex: humanizeDuration(1000000000000, {largest: 3, conjunction: true, language: 'fr'}) => 31 ans, 8 mois et 1 semaine

ex language config:

 fr: {
      y: function (c) { return 'an' + (c !== 1 ? 's' : '') },
      mo: 'mois',
      w: function (c) { return 'semaine' + (c !== 1 ? 's' : '') },
      d: function (c) { return 'jour' + (c !== 1 ? 's' : '') },
      h: function (c) { return 'heure' + (c !== 1 ? 's' : '') },
      m: function (c) { return 'minute' + (c !== 1 ? 's' : '') },
      s: function (c) { return 'seconde' + (c !== 1 ? 's' : '') },
      ms: function (c) { return 'milliseconde' + (c !== 1 ? 's' : '') },
      decimal: ',',
      conjunctionDefaults: {
         conjunction: ' et ',
         serialComma: false
      }
    },

I can easily make a pull request with needed code to make it work, but, I can't get all rules for each languages.

EvanHahn commented 7 years ago

I think this is a good idea but I'd prefer it to be part of another module—I'm trying to avoid adding new features to this library.

If you want to make your own, I'm happy to link to it from the readme!