index.js 6.3 KB

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