cullophid / date-fp

Functional programming date manipulation library
121 stars 17 forks source link

I18n #34

Open cullophid opened 8 years ago

cullophid commented 8 years ago

Add simple i18n support

gsantiago commented 6 years ago

@cullophid What about i18n support?

gsantiago commented 6 years ago

I think we could create a function called formatWithLocale() which works exactly like format but receives a locale object as first argument. Then, the format function could just be a curried version of formatWithLocale:

const format = formatWithLocale(DEFAULT_LOCALE)

With this approach, I could create formatters with any locale:

import { formatWithLocale } from 'date-fp'

// I can define my own locale
const LOCALE_PT_BR = {
  MONTHS: ...,
  WEEKDAYS: ...,
  ...
}

export const formatPtBr = formatWithLocale(LOCALE_PT_BR) 

It would be nice to have some locales available in the package too:

import { formatWithLocale } from 'date-fp'
import LOCALE_PT_BR from 'date-fp/locales/pt-br'

export const formatPtBr = formatWithLocale(LOCALE_PT_BR)

@cullophid, what you think?

cullophid commented 6 years ago

That sounds like a great idea! I would merge that PR ;)

mgtitimoli commented 6 years ago

IMO the library should stay as it is, or expand but leaving i18n outside of the movie as that can be handled by Intl.DateTimeFormat.