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

Current model is unable to express some languages #25

Open
balazsbotond opened this issue Oct 7, 2020 · 2 comments
Open

Current model is unable to express some languages #25

balazsbotond opened this issue Oct 7, 2020 · 2 comments

Comments

@balazsbotond
Copy link

balazsbotond commented Oct 7, 2020

I really like small and focused libraries like this one!

I tried to add Hungarian but the words for the time units ("year", "month", etc.) need to be different depending on whether the date is in the past or the future. Looks like disTime doesn't support that yet.

I don't know what your goals are with this library but if you want to support as many languages as possible, I would suggest making each language a function instead of a config object, like this:

'en': function (majorValue, majorUnit, minorValue, minorUnit, isFuture) { ... }

A couple of examples to show how I think this could work:

Example majorValue majorUnit minorValue minorUnit isFuture
4 years and 3 months ago 4 'year' 3 'month' false
4 years ago 4 'year' undefined undefined false
in 4 years 4 'year' undefined undefined true
in 4 years and 3 months 4 'year' 3 'month' true

There could be a default implementation for the majority of languages which could accept a config object similar to the one currently used:

'en': defaultTranslator({
  words: {
    'preAgo': '',
    'postAgo': 'ago',
    'and': 'and',
    'inFuture': 'in',
    'postInFuture': ''
  },
  year: ['year', 'years'],
  month: ['month', 'months'],
  week: ['week', 'weeks'],
  day: ['day', 'days'],
  hour: ['hour', 'hours'],
  minute: ['minute', 'minutes'],
  second: ['second', 'seconds']
})

And weird languages like Hungarian, Russian and Ukrainian could use their own custom implementation (this would also remove the need for the mode key in the config object).

What do you think? If you like this solution I can put up a PR with the necessary changes.

@SimonWaldherr
Copy link
Owner

sounds good to me 👍

@balazsbotond
Copy link
Author

sounds good to me 👍

Great, I'll start working on it and keep you updated.

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

2 participants