localize.cjs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. "use strict";
  2. exports.localize = void 0;
  3. var _index = require("../../_lib/buildLocalizeFn.cjs");
  4. const eraValues = {
  5. narrow: ["B", "A"],
  6. abbreviated: ["BC", "AD"],
  7. wide: ["Before Christ", "Anno Domini"],
  8. };
  9. const quarterValues = {
  10. narrow: ["1", "2", "3", "4"],
  11. abbreviated: ["Q1", "Q2", "Q3", "Q4"],
  12. wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
  13. };
  14. // Note: in English, the names of days of the week and months are capitalized.
  15. // If you are making a new locale based on this one, check if the same is true for the language you're working on.
  16. // Generally, formatted dates should look like they are in the middle of a sentence,
  17. // e.g. in Spanish language the weekdays and months should be in the lowercase.
  18. const monthValues = {
  19. narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
  20. abbreviated: [
  21. "Jan",
  22. "Feb",
  23. "Mar",
  24. "Apr",
  25. "May",
  26. "Jun",
  27. "Jul",
  28. "Aug",
  29. "Sep",
  30. "Oct",
  31. "Nov",
  32. "Dec",
  33. ],
  34. wide: [
  35. "January",
  36. "February",
  37. "March",
  38. "April",
  39. "May",
  40. "June",
  41. "July",
  42. "August",
  43. "September",
  44. "October",
  45. "November",
  46. "December",
  47. ],
  48. };
  49. const dayValues = {
  50. narrow: ["S", "M", "T", "W", "T", "F", "S"],
  51. short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
  52. abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  53. wide: [
  54. "Sunday",
  55. "Monday",
  56. "Tuesday",
  57. "Wednesday",
  58. "Thursday",
  59. "Friday",
  60. "Saturday",
  61. ],
  62. };
  63. const dayPeriodValues = {
  64. narrow: {
  65. am: "a",
  66. pm: "p",
  67. midnight: "mi",
  68. noon: "n",
  69. morning: "morning",
  70. afternoon: "afternoon",
  71. evening: "evening",
  72. night: "night",
  73. },
  74. abbreviated: {
  75. am: "AM",
  76. pm: "PM",
  77. midnight: "midnight",
  78. noon: "noon",
  79. morning: "morning",
  80. afternoon: "afternoon",
  81. evening: "evening",
  82. night: "night",
  83. },
  84. wide: {
  85. am: "a.m.",
  86. pm: "p.m.",
  87. midnight: "midnight",
  88. noon: "noon",
  89. morning: "morning",
  90. afternoon: "afternoon",
  91. evening: "evening",
  92. night: "night",
  93. },
  94. };
  95. const formattingDayPeriodValues = {
  96. narrow: {
  97. am: "a",
  98. pm: "p",
  99. midnight: "mi",
  100. noon: "n",
  101. morning: "in the morning",
  102. afternoon: "in the afternoon",
  103. evening: "in the evening",
  104. night: "at night",
  105. },
  106. abbreviated: {
  107. am: "AM",
  108. pm: "PM",
  109. midnight: "midnight",
  110. noon: "noon",
  111. morning: "in the morning",
  112. afternoon: "in the afternoon",
  113. evening: "in the evening",
  114. night: "at night",
  115. },
  116. wide: {
  117. am: "a.m.",
  118. pm: "p.m.",
  119. midnight: "midnight",
  120. noon: "noon",
  121. morning: "in the morning",
  122. afternoon: "in the afternoon",
  123. evening: "in the evening",
  124. night: "at night",
  125. },
  126. };
  127. const ordinalNumber = (dirtyNumber, _options) => {
  128. const number = Number(dirtyNumber);
  129. // If ordinal numbers depend on context, for example,
  130. // if they are different for different grammatical genders,
  131. // use `options.unit`.
  132. //
  133. // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
  134. // 'day', 'hour', 'minute', 'second'.
  135. const rem100 = number % 100;
  136. if (rem100 > 20 || rem100 < 10) {
  137. switch (rem100 % 10) {
  138. case 1:
  139. return number + "st";
  140. case 2:
  141. return number + "nd";
  142. case 3:
  143. return number + "rd";
  144. }
  145. }
  146. return number + "th";
  147. };
  148. const localize = (exports.localize = {
  149. ordinalNumber,
  150. era: (0, _index.buildLocalizeFn)({
  151. values: eraValues,
  152. defaultWidth: "wide",
  153. }),
  154. quarter: (0, _index.buildLocalizeFn)({
  155. values: quarterValues,
  156. defaultWidth: "wide",
  157. argumentCallback: (quarter) => quarter - 1,
  158. }),
  159. month: (0, _index.buildLocalizeFn)({
  160. values: monthValues,
  161. defaultWidth: "wide",
  162. }),
  163. day: (0, _index.buildLocalizeFn)({
  164. values: dayValues,
  165. defaultWidth: "wide",
  166. }),
  167. dayPeriod: (0, _index.buildLocalizeFn)({
  168. values: dayPeriodValues,
  169. defaultWidth: "wide",
  170. formattingValues: formattingDayPeriodValues,
  171. defaultFormattingWidth: "wide",
  172. }),
  173. });