localize.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { buildLocalizeFn } from "../../_lib/buildLocalizeFn.js";
  2. const eraValues = {
  3. narrow: ["P", "M"],
  4. abbreviated: ["PK", "MK"],
  5. wide: ["Para Krishtit", "Mbas Krishtit"],
  6. };
  7. const quarterValues = {
  8. narrow: ["1", "2", "3", "4"],
  9. abbreviated: ["Q1", "Q2", "Q3", "Q4"],
  10. wide: ["4-mujori I", "4-mujori II", "4-mujori III", "4-mujori IV"],
  11. };
  12. // Note: in English, the names of days of the week and months are capitalized.
  13. // If you are making a new locale based on this one, check if the same is true for the language you're working on.
  14. // Generally, formatted dates should look like they are in the middle of a sentence,
  15. // e.g. in Spanish language the weekdays and months should be in the lowercase.
  16. const monthValues = {
  17. narrow: ["J", "S", "M", "P", "M", "Q", "K", "G", "S", "T", "N", "D"],
  18. abbreviated: [
  19. "Jan",
  20. "Shk",
  21. "Mar",
  22. "Pri",
  23. "Maj",
  24. "Qer",
  25. "Kor",
  26. "Gus",
  27. "Sht",
  28. "Tet",
  29. "Nën",
  30. "Dhj",
  31. ],
  32. wide: [
  33. "Janar",
  34. "Shkurt",
  35. "Mars",
  36. "Prill",
  37. "Maj",
  38. "Qershor",
  39. "Korrik",
  40. "Gusht",
  41. "Shtator",
  42. "Tetor",
  43. "Nëntor",
  44. "Dhjetor",
  45. ],
  46. };
  47. const dayValues = {
  48. narrow: ["D", "H", "M", "M", "E", "P", "S"],
  49. short: ["Di", "Hë", "Ma", "Më", "En", "Pr", "Sh"],
  50. abbreviated: ["Die", "Hën", "Mar", "Mër", "Enj", "Pre", "Sht"],
  51. wide: ["Dielë", "Hënë", "Martë", "Mërkurë", "Enjte", "Premte", "Shtunë"],
  52. };
  53. const dayPeriodValues = {
  54. narrow: {
  55. am: "p",
  56. pm: "m",
  57. midnight: "m",
  58. noon: "d",
  59. morning: "mëngjes",
  60. afternoon: "dite",
  61. evening: "mbrëmje",
  62. night: "natë",
  63. },
  64. abbreviated: {
  65. am: "PD",
  66. pm: "MD",
  67. midnight: "mesnëtë",
  68. noon: "drek",
  69. morning: "mëngjes",
  70. afternoon: "mbasdite",
  71. evening: "mbrëmje",
  72. night: "natë",
  73. },
  74. wide: {
  75. am: "p.d.",
  76. pm: "m.d.",
  77. midnight: "mesnëtë",
  78. noon: "drek",
  79. morning: "mëngjes",
  80. afternoon: "mbasdite",
  81. evening: "mbrëmje",
  82. night: "natë",
  83. },
  84. };
  85. const formattingDayPeriodValues = {
  86. narrow: {
  87. am: "p",
  88. pm: "m",
  89. midnight: "m",
  90. noon: "d",
  91. morning: "në mëngjes",
  92. afternoon: "në mbasdite",
  93. evening: "në mbrëmje",
  94. night: "në mesnatë",
  95. },
  96. abbreviated: {
  97. am: "PD",
  98. pm: "MD",
  99. midnight: "mesnatë",
  100. noon: "drek",
  101. morning: "në mëngjes",
  102. afternoon: "në mbasdite",
  103. evening: "në mbrëmje",
  104. night: "në mesnatë",
  105. },
  106. wide: {
  107. am: "p.d.",
  108. pm: "m.d.",
  109. midnight: "mesnatë",
  110. noon: "drek",
  111. morning: "në mëngjes",
  112. afternoon: "në mbasdite",
  113. evening: "në mbrëmje",
  114. night: "në mesnatë",
  115. },
  116. };
  117. const ordinalNumber = (dirtyNumber, options) => {
  118. const number = Number(dirtyNumber);
  119. if (options?.unit === "hour") return String(number);
  120. if (number === 1) return number + "-rë";
  121. if (number === 4) return number + "t";
  122. return number + "-të";
  123. };
  124. export const localize = {
  125. ordinalNumber,
  126. era: buildLocalizeFn({
  127. values: eraValues,
  128. defaultWidth: "wide",
  129. }),
  130. quarter: buildLocalizeFn({
  131. values: quarterValues,
  132. defaultWidth: "wide",
  133. argumentCallback: (quarter) => quarter - 1,
  134. }),
  135. month: buildLocalizeFn({
  136. values: monthValues,
  137. defaultWidth: "wide",
  138. }),
  139. day: buildLocalizeFn({
  140. values: dayValues,
  141. defaultWidth: "wide",
  142. }),
  143. dayPeriod: buildLocalizeFn({
  144. values: dayPeriodValues,
  145. defaultWidth: "wide",
  146. formattingValues: formattingDayPeriodValues,
  147. defaultFormattingWidth: "wide",
  148. }),
  149. };