be.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Belarusian [be]
  2. import dayjs from '../index';
  3. var monthFormat = 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_');
  4. var monthStandalone = 'студзень_лютый_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_');
  5. var monthShortFormat = 'студ_лют_сак_крас_трав_чэрв_ліп_жнів_вер_каст_ліст_снеж.'.split('_');
  6. var monthShortStandalone = 'студ_лют_сак_крас_трав_чэрв_ліп_жнів_вер_каст_ліст_снеж'.split('_');
  7. var MONTHS_IN_FORMAT = /D[oD]?(\[[^[\]]*\]|\s)+MMMM?/;
  8. function plural(word, num) {
  9. var forms = word.split('_');
  10. return num % 10 === 1 && num % 100 !== 11 ? forms[0] : num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) ? forms[1] : forms[2]; // eslint-disable-line
  11. }
  12. function relativeTimeWithPlural(number, withoutSuffix, key) {
  13. var format = {
  14. ss: withoutSuffix ? 'секунда_секунды_секунд' : 'секунду_секунды_секунд',
  15. mm: withoutSuffix ? 'хвіліна_хвіліны_хвілін' : 'хвіліну_хвіліны_хвілін',
  16. hh: withoutSuffix ? 'гадзіна_гадзіны_гадзін' : 'гадзіну_гадзіны_гадзін',
  17. dd: 'дзень_дні_дзён',
  18. MM: 'месяц_месяцы_месяцаў',
  19. yy: 'год_гады_гадоў'
  20. };
  21. if (key === 'm') {
  22. return withoutSuffix ? 'хвіліна' : 'хвіліну';
  23. } else if (key === 'h') {
  24. return withoutSuffix ? 'гадзіна' : 'гадзіну';
  25. }
  26. return number + " " + plural(format[key], +number);
  27. }
  28. var months = function months(dayjsInstance, format) {
  29. if (MONTHS_IN_FORMAT.test(format)) {
  30. return monthFormat[dayjsInstance.month()];
  31. }
  32. return monthStandalone[dayjsInstance.month()];
  33. };
  34. months.s = monthStandalone;
  35. months.f = monthFormat;
  36. var monthsShort = function monthsShort(dayjsInstance, format) {
  37. if (MONTHS_IN_FORMAT.test(format)) {
  38. return monthShortFormat[dayjsInstance.month()];
  39. }
  40. return monthShortStandalone[dayjsInstance.month()];
  41. };
  42. monthsShort.s = monthShortStandalone;
  43. monthsShort.f = monthShortFormat;
  44. var locale = {
  45. name: 'be',
  46. weekdays: 'нядзеля_панядзелак_аўторак_серада_чацвер_пятніца_субота'.split('_'),
  47. weekdaysShort: 'няд_пнд_аўт_сер_чцв_пят_суб'.split('_'),
  48. weekdaysMin: 'нд_пн_аў_ср_чц_пт_сб'.split('_'),
  49. months: months,
  50. monthsShort: monthsShort,
  51. weekStart: 1,
  52. yearStart: 4,
  53. formats: {
  54. LT: 'HH:mm',
  55. LTS: 'HH:mm:ss',
  56. L: 'DD.MM.YYYY',
  57. LL: 'D MMMM YYYY г.',
  58. LLL: 'D MMMM YYYY г., HH:mm',
  59. LLLL: 'dddd, D MMMM YYYY г., HH:mm'
  60. },
  61. relativeTime: {
  62. future: 'праз %s',
  63. past: '%s таму',
  64. s: 'некалькі секунд',
  65. m: relativeTimeWithPlural,
  66. mm: relativeTimeWithPlural,
  67. h: relativeTimeWithPlural,
  68. hh: relativeTimeWithPlural,
  69. d: 'дзень',
  70. dd: relativeTimeWithPlural,
  71. M: 'месяц',
  72. MM: relativeTimeWithPlural,
  73. y: 'год',
  74. yy: relativeTimeWithPlural
  75. },
  76. ordinal: function ordinal(n) {
  77. return n;
  78. },
  79. meridiem: function meridiem(hour) {
  80. if (hour < 4) {
  81. return 'ночы';
  82. } else if (hour < 12) {
  83. return 'раніцы';
  84. } else if (hour < 17) {
  85. return 'дня';
  86. }
  87. return 'вечара';
  88. }
  89. };
  90. dayjs.locale(locale, null, true);
  91. export default locale;