localize.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { buildLocalizeFn } from "../../_lib/buildLocalizeFn.js";
  2. const eraValues = {
  3. narrow: ["R", "A"],
  4. abbreviated: ["RC", "AD"],
  5. wide: ["ro Chrìosta", "anno domini"],
  6. };
  7. const quarterValues = {
  8. narrow: ["1", "2", "3", "4"],
  9. abbreviated: ["C1", "C2", "C3", "C4"],
  10. wide: [
  11. "a' chiad chairteal",
  12. "an dàrna cairteal",
  13. "an treas cairteal",
  14. "an ceathramh cairteal",
  15. ],
  16. };
  17. // Note: in English, the names of days of the week and months are capitalized.
  18. // If you are making a new locale based on this one, check if the same is true for the language you're working on.
  19. // Generally, formatted dates should look like they are in the middle of a sentence,
  20. // e.g. in Spanish language the weekdays and months should be in the lowercase.
  21. const monthValues = {
  22. narrow: ["F", "G", "M", "G", "C", "Ò", "I", "L", "S", "D", "S", "D"],
  23. abbreviated: [
  24. "Faoi",
  25. "Gear",
  26. "Màrt",
  27. "Gibl",
  28. "Cèit",
  29. "Ògmh",
  30. "Iuch",
  31. "Lùn",
  32. "Sult",
  33. "Dàmh",
  34. "Samh",
  35. "Dùbh",
  36. ],
  37. wide: [
  38. "Am Faoilleach",
  39. "An Gearran",
  40. "Am Màrt",
  41. "An Giblean",
  42. "An Cèitean",
  43. "An t-Ògmhios",
  44. "An t-Iuchar",
  45. "An Lùnastal",
  46. "An t-Sultain",
  47. "An Dàmhair",
  48. "An t-Samhain",
  49. "An Dùbhlachd",
  50. ],
  51. };
  52. const dayValues = {
  53. narrow: ["D", "L", "M", "C", "A", "H", "S"],
  54. short: ["Dò", "Lu", "Mà", "Ci", "Ar", "Ha", "Sa"],
  55. abbreviated: ["Did", "Dil", "Dim", "Dic", "Dia", "Dih", "Dis"],
  56. wide: [
  57. "Didòmhnaich",
  58. "Diluain",
  59. "Dimàirt",
  60. "Diciadain",
  61. "Diardaoin",
  62. "Dihaoine",
  63. "Disathairne",
  64. ],
  65. };
  66. const dayPeriodValues = {
  67. narrow: {
  68. am: "m",
  69. pm: "f",
  70. midnight: "m.o.",
  71. noon: "m.l.",
  72. morning: "madainn",
  73. afternoon: "feasgar",
  74. evening: "feasgar",
  75. night: "oidhche",
  76. },
  77. abbreviated: {
  78. am: "M.",
  79. pm: "F.",
  80. midnight: "meadhan oidhche",
  81. noon: "meadhan là",
  82. morning: "madainn",
  83. afternoon: "feasgar",
  84. evening: "feasgar",
  85. night: "oidhche",
  86. },
  87. wide: {
  88. am: "m.",
  89. pm: "f.",
  90. midnight: "meadhan oidhche",
  91. noon: "meadhan là",
  92. morning: "madainn",
  93. afternoon: "feasgar",
  94. evening: "feasgar",
  95. night: "oidhche",
  96. },
  97. };
  98. const formattingDayPeriodValues = {
  99. narrow: {
  100. am: "m",
  101. pm: "f",
  102. midnight: "m.o.",
  103. noon: "m.l.",
  104. morning: "sa mhadainn",
  105. afternoon: "feasgar",
  106. evening: "feasgar",
  107. night: "air an oidhche",
  108. },
  109. abbreviated: {
  110. am: "M.",
  111. pm: "F.",
  112. midnight: "meadhan oidhche",
  113. noon: "meadhan là",
  114. morning: "sa mhadainn",
  115. afternoon: "feasgar",
  116. evening: "feasgar",
  117. night: "air an oidhche",
  118. },
  119. wide: {
  120. am: "m.",
  121. pm: "f.",
  122. midnight: "meadhan oidhche",
  123. noon: "meadhan là",
  124. morning: "sa mhadainn",
  125. afternoon: "feasgar",
  126. evening: "feasgar",
  127. night: "air an oidhche",
  128. },
  129. };
  130. const ordinalNumber = (dirtyNumber) => {
  131. const number = Number(dirtyNumber);
  132. const rem100 = number % 100;
  133. if (rem100 > 20 || rem100 < 10) {
  134. switch (rem100 % 10) {
  135. case 1:
  136. return number + "d";
  137. case 2:
  138. return number + "na";
  139. }
  140. }
  141. if (rem100 === 12) {
  142. return number + "na";
  143. }
  144. return number + "mh";
  145. };
  146. export const localize = {
  147. ordinalNumber,
  148. era: buildLocalizeFn({
  149. values: eraValues,
  150. defaultWidth: "wide",
  151. }),
  152. quarter: buildLocalizeFn({
  153. values: quarterValues,
  154. defaultWidth: "wide",
  155. argumentCallback: (quarter) => quarter - 1,
  156. }),
  157. month: buildLocalizeFn({
  158. values: monthValues,
  159. defaultWidth: "wide",
  160. }),
  161. day: buildLocalizeFn({
  162. values: dayValues,
  163. defaultWidth: "wide",
  164. }),
  165. dayPeriod: buildLocalizeFn({
  166. values: dayPeriodValues,
  167. defaultWidth: "wide",
  168. formattingValues: formattingDayPeriodValues,
  169. defaultFormattingWidth: "wide",
  170. }),
  171. };