0.2.1 • Published 8 years ago

fecha-locales v0.2.1

Weekly downloads
4
License
MIT
Repository
-
Last release
8 years ago

Installation * Npm #+begin_src bash npm install --save fecha-locales #+end_src *** Browser #+begin_src html

#+end_src Usage * Npm Import/require the locale(s) you need, and put the one you want to use as fecha.i18n

#+begin_src javascript import fr from 'fecha-locales/locales/fr';

fecha.i18n = fr; #+end_src *** Browser For browser,

  • Include fecha-locales before your app (i.e script that is going to use fecha-locales).
  • Doing so will export ~window.fechaLocales~ object
  • You can add multiple locales
  • All the locales you create will be added to ~window.fechaLocales.~
  • In your app, you can now do ~fecha.i18n = fechaLocales.~ #+begin_src javascript // In html

// In app.js fecha.i18n = fechaLocales.; #+endsrc Credits All the fecha-locales are built from [https://github.com/moment/moment]. All credit for collecting the locales go to momentjs. This module uses a small build script to convert moment-locales to fecha friendly locales (i.e which can be put simply as value of ~fecha.i18n~) FAQ *** The locale I need is not present in ~fecha-locales/locales/~ but it is present in moment-locales All the moment-locales couldn't get converted to fecha. So the ones which failed to convert are placed as ~fecha-locales/locales/~, but please don't use them. If you need a locale which is present as ~fecha-locales/locales/_~, please do one of these:

  • Create an issue and I'll fix it
  • Create a pull request with the fix. To create a fix:
    • Clone/fork this repository, cd to it, and install npm dependencies #+begin_src bash git clone https://github.com/channikhabra/fecha-locales.git cd fecha-locales npm install #+end_src
    • Run build-locales script #+begin_src javascript npm run build-locales #+end_src
    • Now you'll see some messages in the console which will tell you which properties are facing problems. Search for the ~<locale-name.js>~ to see which properties you need to fix. For example, if you're fixing ~es~ locale, you need to look for these messages: #+begin_src bash Invalid value for monthsShort of "es.js". Please fix it manually. Invalid value for DoFn of "es.js". Please fix it manually. #+end_src
    • Create ~fecha-locales/locale-builder/fixers/.js~ file
    • Now ~module.exports~ an object from this file, which should contain the keys which are causing problems and put the fixes for them as their values. Make sure you first check ~fecha-locales/locales/_.js~ file for clues. For ~es~ locale, following should fix the building of locale: #+begin_src javascript // fecha-locales/locale-builder/fixers/es.js module.exports = { DoFn: (number) => { // in moment/locales/es, this is given as %dº, but fecha need it to be a function, so we make it a function instead return number + 'º'; }, monthsShort: 'enero', 'feb.', 'marzo', 'abr.', 'mayo', 'jun.', 'jul.', 'agosto', 'sept.', 'oct.', 'nov.', 'dic.' }; #+end_src
    • Now run ~npm run build-locales~ again, and ~fecha-locales/locales/.js~ shall be there.
    • Create a PR (Thanks for creating the PR, you're awesome!) *** Why did you use esprima and friends to convert moment locales to fecha? Wasn't there an easier way of doing so? Not sure about easier, but yes this can be done in other ways. I was feeling fancy so I went with esprima. Besides, this is the most explicit and flexible way of conversion imo.
0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago