Implement Nepali datetime in ROR

Viewed 116

Any idea about nepali datetime implementation on Ruby on rails. Share docs or guide if you have any idea.

Date Picker as:

nepali date time format

And save the date in database.

1 Answers

I have a idea. Well, I make a gem that allow you create a date picker. I don't implemeted all languages but you can implement in your. I'll used Portuguese language as example, I created a file pt.js for Portuguese Language(my Language) in assets/javascript folder then you'll need create something like np.js and adapt js file for your Language.

https://github.com/ariclinis/flatpickr-datepicker-rails

Read the Documentation, you'll need make two changes:

  1. Import np.js file on your application.js, like this:

    //= require("np")

  2. On your config_date you just need add attr "locale"

var config_date = {

  dateFormat: "d-m-Y",
  locale: "np"

};

That's all, I hope this helps.

My file pt.js (Change var Portuguese to var Nepali and pt to np):

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pt = {}));
}(this, (function (exports) { 'use strict';

  var fp = typeof window !== "undefined" && window.flatpickr !== undefined
      ? window.flatpickr
      : {
          l10ns: {},
      };
  var Portuguese = {
      weekdays: {
          shorthand: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
          longhand: [
              "Domingo",
              "Segunda-feira",
              "Terça-feira",
              "Quarta-feira",
              "Quinta-feira",
              "Sexta-feira",
              "Sábado",
          ],
      },
      months: {
          shorthand: [
              "Jan",
              "Fev",
              "Mar",
              "Abr",
              "Mai",
              "Jun",
              "Jul",
              "Ago",
              "Set",
              "Out",
              "Nov",
              "Dez",
          ],
          longhand: [
              "Janeiro",
              "Fevereiro",
              "Março",
              "Abril",
              "Maio",
              "Junho",
              "Julho",
              "Agosto",
              "Setembro",
              "Outubro",
              "Novembro",
              "Dezembro",
          ],
      },
      rangeSeparator: " até ",
      time_24hr: true,
  };
  fp.l10ns.pt = Portuguese;
  var pt = fp.l10ns;

  exports.Portuguese = Portuguese;
  exports.default = pt;

  Object.defineProperty(exports, '__esModule', { value: true });

})));
Related