index.js 6.9 KB

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