localize.cjs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. "use strict";
  2. exports.localize = void 0;
  3. var _index = require("../../_lib/buildLocalizeFn.cjs");
  4. // Vietnamese locale reference: http://www.localeplanet.com/icu/vi-VN/index.html
  5. // Capitalization reference: http://hcmup.edu.vn/index.php?option=com_content&view=article&id=4106%3Avit-hoa-trong-vn-bn-hanh-chinh&catid=2345%3Atham-kho&Itemid=4103&lang=vi&site=134
  6. const eraValues = {
  7. narrow: ["TCN", "SCN"],
  8. abbreviated: ["trước CN", "sau CN"],
  9. wide: ["trước Công Nguyên", "sau Công Nguyên"],
  10. };
  11. const quarterValues = {
  12. narrow: ["1", "2", "3", "4"],
  13. abbreviated: ["Q1", "Q2", "Q3", "Q4"],
  14. wide: ["Quý 1", "Quý 2", "Quý 3", "Quý 4"],
  15. };
  16. const formattingQuarterValues = {
  17. narrow: ["1", "2", "3", "4"],
  18. abbreviated: ["Q1", "Q2", "Q3", "Q4"],
  19. // I notice many news outlet use this "quý II/2018"
  20. wide: ["quý I", "quý II", "quý III", "quý IV"],
  21. };
  22. // Note: in English, the names of days of the week and months are capitalized.
  23. // If you are making a new locale based on this one, check if the same is true for the language you're working on.
  24. // Generally, formatted dates should look like they are in the middle of a sentence,
  25. // e.g. in Spanish language the weekdays and months should be in the lowercase.
  26. const monthValues = {
  27. narrow: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
  28. abbreviated: [
  29. "Thg 1",
  30. "Thg 2",
  31. "Thg 3",
  32. "Thg 4",
  33. "Thg 5",
  34. "Thg 6",
  35. "Thg 7",
  36. "Thg 8",
  37. "Thg 9",
  38. "Thg 10",
  39. "Thg 11",
  40. "Thg 12",
  41. ],
  42. wide: [
  43. "Tháng Một",
  44. "Tháng Hai",
  45. "Tháng Ba",
  46. "Tháng Tư",
  47. "Tháng Năm",
  48. "Tháng Sáu",
  49. "Tháng Bảy",
  50. "Tháng Tám",
  51. "Tháng Chín",
  52. "Tháng Mười",
  53. "Tháng Mười Một",
  54. "Tháng Mười Hai",
  55. ],
  56. };
  57. // In Vietnamese date formatting, month number less than 10 expected to have leading zero
  58. const formattingMonthValues = {
  59. narrow: [
  60. "01",
  61. "02",
  62. "03",
  63. "04",
  64. "05",
  65. "06",
  66. "07",
  67. "08",
  68. "09",
  69. "10",
  70. "11",
  71. "12",
  72. ],
  73. abbreviated: [
  74. "thg 1",
  75. "thg 2",
  76. "thg 3",
  77. "thg 4",
  78. "thg 5",
  79. "thg 6",
  80. "thg 7",
  81. "thg 8",
  82. "thg 9",
  83. "thg 10",
  84. "thg 11",
  85. "thg 12",
  86. ],
  87. wide: [
  88. "tháng 01",
  89. "tháng 02",
  90. "tháng 03",
  91. "tháng 04",
  92. "tháng 05",
  93. "tháng 06",
  94. "tháng 07",
  95. "tháng 08",
  96. "tháng 09",
  97. "tháng 10",
  98. "tháng 11",
  99. "tháng 12",
  100. ],
  101. };
  102. const dayValues = {
  103. narrow: ["CN", "T2", "T3", "T4", "T5", "T6", "T7"],
  104. short: ["CN", "Th 2", "Th 3", "Th 4", "Th 5", "Th 6", "Th 7"],
  105. abbreviated: ["CN", "Thứ 2", "Thứ 3", "Thứ 4", "Thứ 5", "Thứ 6", "Thứ 7"],
  106. wide: [
  107. "Chủ Nhật",
  108. "Thứ Hai",
  109. "Thứ Ba",
  110. "Thứ Tư",
  111. "Thứ Năm",
  112. "Thứ Sáu",
  113. "Thứ Bảy",
  114. ],
  115. };
  116. // Vietnamese are used to AM/PM borrowing from English, hence `narrow` and
  117. // `abbreviated` are just like English but I'm leaving the `wide`
  118. // format being localized with abbreviations found in some systems (SÁng / CHiều);
  119. // however, personally, I don't think `Chiều` sounds appropriate for `PM`
  120. const dayPeriodValues = {
  121. // narrow date period is extremely rare in Vietnamese
  122. // I used abbreviated form for noon, morning and afternoon
  123. // which are regconizable by Vietnamese, others cannot be any shorter
  124. narrow: {
  125. am: "am",
  126. pm: "pm",
  127. midnight: "nửa đêm",
  128. noon: "tr",
  129. morning: "sg",
  130. afternoon: "ch",
  131. evening: "tối",
  132. night: "đêm",
  133. },
  134. abbreviated: {
  135. am: "AM",
  136. pm: "PM",
  137. midnight: "nửa đêm",
  138. noon: "trưa",
  139. morning: "sáng",
  140. afternoon: "chiều",
  141. evening: "tối",
  142. night: "đêm",
  143. },
  144. wide: {
  145. am: "SA",
  146. pm: "CH",
  147. midnight: "nửa đêm",
  148. noon: "trưa",
  149. morning: "sáng",
  150. afternoon: "chiều",
  151. evening: "tối",
  152. night: "đêm",
  153. },
  154. };
  155. const formattingDayPeriodValues = {
  156. narrow: {
  157. am: "am",
  158. pm: "pm",
  159. midnight: "nửa đêm",
  160. noon: "tr",
  161. morning: "sg",
  162. afternoon: "ch",
  163. evening: "tối",
  164. night: "đêm",
  165. },
  166. abbreviated: {
  167. am: "AM",
  168. pm: "PM",
  169. midnight: "nửa đêm",
  170. noon: "trưa",
  171. morning: "sáng",
  172. afternoon: "chiều",
  173. evening: "tối",
  174. night: "đêm",
  175. },
  176. wide: {
  177. am: "SA",
  178. pm: "CH",
  179. midnight: "nửa đêm",
  180. noon: "giữa trưa",
  181. morning: "vào buổi sáng",
  182. afternoon: "vào buổi chiều",
  183. evening: "vào buổi tối",
  184. night: "vào ban đêm",
  185. },
  186. };
  187. const ordinalNumber = (dirtyNumber, options) => {
  188. const number = Number(dirtyNumber);
  189. const unit = options?.unit;
  190. if (unit === "quarter") {
  191. // many news outlets use "quý I"...
  192. switch (number) {
  193. case 1:
  194. return "I";
  195. case 2:
  196. return "II";
  197. case 3:
  198. return "III";
  199. case 4:
  200. return "IV";
  201. }
  202. } else if (unit === "day") {
  203. // day of week in Vietnamese has ordinal number meaning,
  204. // so we should use them, else it'll sound weird
  205. switch (number) {
  206. case 1:
  207. return "thứ 2"; // meaning 2nd day but it's the first day of the week :D
  208. case 2:
  209. return "thứ 3"; // meaning 3rd day
  210. case 3:
  211. return "thứ 4"; // meaning 4th day and so on
  212. case 4:
  213. return "thứ 5";
  214. case 5:
  215. return "thứ 6";
  216. case 6:
  217. return "thứ 7";
  218. case 7:
  219. return "chủ nhật"; // meaning Sunday, there's no 8th day :D
  220. }
  221. } else if (unit === "week") {
  222. if (number === 1) {
  223. return "thứ nhất";
  224. } else {
  225. return "thứ " + number;
  226. }
  227. } else if (unit === "dayOfYear") {
  228. if (number === 1) {
  229. return "đầu tiên";
  230. } else {
  231. return "thứ " + number;
  232. }
  233. }
  234. // there are no different forms of ordinal numbers in Vietnamese
  235. return String(number);
  236. };
  237. const localize = (exports.localize = {
  238. ordinalNumber,
  239. era: (0, _index.buildLocalizeFn)({
  240. values: eraValues,
  241. defaultWidth: "wide",
  242. }),
  243. quarter: (0, _index.buildLocalizeFn)({
  244. values: quarterValues,
  245. defaultWidth: "wide",
  246. formattingValues: formattingQuarterValues,
  247. defaultFormattingWidth: "wide",
  248. argumentCallback: (quarter) => quarter - 1,
  249. }),
  250. month: (0, _index.buildLocalizeFn)({
  251. values: monthValues,
  252. defaultWidth: "wide",
  253. formattingValues: formattingMonthValues,
  254. defaultFormattingWidth: "wide",
  255. }),
  256. day: (0, _index.buildLocalizeFn)({
  257. values: dayValues,
  258. defaultWidth: "wide",
  259. }),
  260. dayPeriod: (0, _index.buildLocalizeFn)({
  261. values: dayPeriodValues,
  262. defaultWidth: "wide",
  263. formattingValues: formattingDayPeriodValues,
  264. defaultFormattingWidth: "wide",
  265. }),
  266. });