Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VI locale for v2 #846

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion outdatedLocales.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
"sr",
"th",
"tr",
"vi",
"zh-TW"
]
8 changes: 4 additions & 4 deletions src/locale/vi/_lib/formatDistance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var formatDistanceLocale = {
},

aboutXHours: {
one: 'khoảng 1 tiếng',
other: 'khoảng {{count}} tiếng'
one: 'khoảng 1 giờ',
other: 'khoảng {{count}} giờ'
},

xHours: {
one: '1 tiếng',
other: '{{count}} tiếng'
one: '1 giờ',
other: '{{count}} giờ'
},

xDays: {
Expand Down
8 changes: 4 additions & 4 deletions src/locale/vi/_lib/formatDistance/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ describe('vi locale > formatDistance', function () {
describe('aboutXHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 1) === 'khoảng 1 tiếng')
assert(formatDistance('aboutXHours', 1) === 'khoảng 1 giờ')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 2) === 'khoảng 2 tiếng')
assert(formatDistance('aboutXHours', 2) === 'khoảng 2 giờ')
})
})
})

describe('xHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xHours', 1) === '1 tiếng')
assert(formatDistance('xHours', 1) === '1 giờ')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xHours', 2) === '2 tiếng')
assert(formatDistance('xHours', 2) === '2 giờ')
})
})
})
Expand Down
55 changes: 42 additions & 13 deletions src/locale/vi/_lib/formatLong/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'

var formatLong = buildFormatLongFn({
// 23:25
LT: 'H:mm',
// 23:25:59
LTS: 'H:mm:ss',
var dateFormats = {
// thứ Sáu, ngày 25 tháng 08 năm 2017
full: "EEEE, 'ngày' d MMMM 'năm' y",
// ngày 25 tháng 08 năm 2017
long: "'ngày' d MMMM 'năm' y",
// 25 thg 08 năm 2017
medium: "d MMM 'năm' y",
// 25/08/2017
L: 'DD/MM/YYYY',
// ngày 25 tháng 8 năm 2017
LL: '[ngày] D [tháng] M [năm] YYYY',
// ngày 25 tháng 8 năm 2017 23:25
LLL: '[ngày] D [tháng] M [năm] YYYY H:mm',
// thứ Sáu, ngày 25 tháng Tám năm 2017 23:25:59
LLLL: 'dddd, [ngày] D MMMM [năm] YYYY H:mm:ss'
})
short: 'dd/MM/y'
}

var timeFormats = {
full: 'HH:mm:ss zzzz',
long: 'HH:mm:ss z',
medium: 'HH:mm:ss',
short: 'HH:mm'
}

var dateTimeFormats = {
// thứ Sáu, ngày 25 tháng 08 năm 2017 23:25:59
full: '{{date}} {{time}}',
// ngày 25 tháng 08 năm 2017 23:25
long: '{{date}} {{time}}',
medium: '{{date}} {{time}}',
short: '{{date}} {{time}}'
}

var formatLong = {
date: buildFormatLongFn({
formats: dateFormats,
defaultWidth: 'full'
}),

time: buildFormatLongFn({
formats: timeFormats,
defaultWidth: 'full'
}),

dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: 'full'
})
}

export default formatLong
12 changes: 6 additions & 6 deletions src/locale/vi/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var formatRelativeLocale = {
lastWeek: 'dddd [tuần trước vào lúc] LT',
yesterday: '[hôm qua vào lúc] LT',
today: '[hôm nay vào lúc] LT',
tomorrow: '[ngày mai vào lúc] LT',
nextWeek: 'dddd [vào lúc] LT',
other: 'L'
lastWeek: "eeee 'tuần trước vào lúc' p",
yesterday: "'hôm qua vào lúc' p",
today: "'hôm nay vào lúc' p",
tomorrow: "'ngày mai vào lúc' p",
nextWeek: "eeee 'tới vào lúc' p",
other: 'P'
}

export default function formatRelative (token, date, baseDate, options) {
Expand Down
222 changes: 159 additions & 63 deletions src/locale/vi/_lib/localize/index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,121 @@
import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index.js'
import buildLocalizeArrayFn from '../../../_lib/buildLocalizeArrayFn/index.js'

// Vietnammese locale reference: http://www.localeplanet.com/icu/vi-VN/index.html
// Vietnamese locale reference: http://www.localeplanet.com/icu/vi-VN/index.html
// 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
var weekdayValues = {
narrow: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'],
short: ['CN', 'thứ 2', 'thứ 3', 'thứ 4', 'thứ 5', 'thứ 6', 'thứ 7'],
long: ['Chủ Nhật', 'thứ Hai', 'thứ Ba', 'thứ Tư', 'thứ Năm', 'thứ Sáu', 'thứ Bảy']

var eraValues = {
narrow: ['TCN', 'SCN'],
abbreviated: ['trước CN', 'sau CN'],
wide: ['trước Công Nguyên', 'sau Công Nguyên']
}

var quarterValues = {
narrow: ['1', '2', '3', '4'],
abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
wide: ['Quý 1', 'Quý 2', 'Quý 3', 'Quý 4']
}

var formattingQuarterValues = {
narrow: ['1', '2', '3', '4'],
abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
// I notice many news outlet use this "quý II/2018"
wide: ['quý I', 'quý II', 'quý III', 'quý IV']
}

// Note: in English, the names of days of the week and months are capitalized.
// If you are making a new locale based on this one, check if the same is true for the language you're working on.
// Generally, formatted dates should look like they are in the middle of a sentence,
// e.g. in Spanish language the weekdays and months should be in the lowercase.
var monthValues = {
short: ['thg 1', 'thg 2', 'thg 3', 'thg 4', 'thg 5', 'thg 6', 'thg 7', 'thg 8', 'thg 9', 'thg 10', 'thg 11', 'thg 12'],
long: ['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']
narrow: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
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'],
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
var formattingMonthValues = {
narrow: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
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'],
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']
}

// `timeOfDay` is used to designate which part of the day it is, when used with 12-hour clock.
// Use the system which is used the most commonly in the locale.
// For example, if the country doesn't use a.m./p.m., you can use `night`/`morning`/`afternoon`/`evening`:
//
// var timeOfDayValues = {
// any: ['in the night', 'in the morning', 'in the afternoon', 'in the evening']
// }
//
// And later:
//
// var localize = {
// // The callback takes the hours as the argument and returns the array index
// timeOfDay: buildLocalizeFn(timeOfDayValues, 'any', function (hours) {
// if (hours >= 17) {
// return 3
// } else if (hours >= 12) {
// return 2
// } else if (hours >= 4) {
// return 1
// } else {
// return 0
// }
// }),
// timesOfDay: buildLocalizeArrayFn(timeOfDayValues, 'any')
// }
var timeOfDayValues = {
// Vietnamese are used to AM/PM borrowing from English, hence `uppercase` and
// `lowercase` are just like English but I'm leaving the `long`
// format being localized with abbreviations found in some systems (SÁng / CHiều);
// however, personally, I don't think `Chiều` sounds appropriate for `PM`
// TODO: for `long` version, the values should be 'sáng' 'trưa' 'chiều' 'tối'
uppercase: ['AM', 'PM'],
lowercase: ['am', 'pm'],
long: ['SA', 'CH']
var dayValues = {
narrow: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'],
short: ['CN', 'Th 2', 'Th 3', 'Th 4', 'Th 5', 'Th 6', 'Th 7'],
abbreviated: ['CN', 'Thứ 2', 'Thứ 3', 'Thứ 4', 'Thứ 5', 'Thứ 6', 'Thứ 7'],
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
// `abbreviated` are just like English but I'm leaving the `wide`
// format being localized with abbreviations found in some systems (SÁng / CHiều);
// however, personally, I don't think `Chiều` sounds appropriate for `PM`
var dayPeriodValues = {
// narrow date period is extremely rare in Vietnamese
// I used abbreviated form for noon, morning and afternoon
// which are regconizable by Vietnamese, others cannot be any shorter
narrow: {
am: 'am',
pm: 'pm',
midnight: 'nửa đêm',
noon: 'tr',
morning: 'sg',
afternoon: 'ch',
evening: 'tối',
night: 'đêm'
},
abbreviated: {
am: 'AM',
pm: 'PM',
midnight: 'nửa đêm',
noon: 'trưa',
morning: 'sáng',
afternoon: 'chiều',
evening: 'tối',
night: 'đêm'
},
wide: {
am: 'SA',
pm: 'CH',
midnight: 'nửa đêm',
noon: 'trưa',
morning: 'sáng',
afternoon: 'chiều',
evening: 'tối',
night: 'đêm'
}
}

var formattingDayPeriodValues = {
narrow: {
am: 'am',
pm: 'pm',
midnight: 'nửa đêm',
noon: 'tr',
morning: 'sg',
afternoon: 'ch',
evening: 'tối',
night: 'đêm'
},
abbreviated: {
am: 'AM',
pm: 'PM',
midnight: 'nửa đêm',
noon: 'trưa',
morning: 'sáng',
afternoon: 'chiều',
evening: 'tối',
night: 'đêm'
},
wide: {
am: 'SA',
pm: 'CH',
midnight: 'nửa đêm',
noon: 'giữa trưa',
morning: 'vào buổi sáng',
afternoon: 'vào buổi chiều',
evening: 'vào buổi tối',
night: 'vào ban đêm'
}
}

// If ordinal numbers depend on context, for example,
Expand All @@ -65,24 +133,26 @@ function ordinalNumber (dirtyNumber, dirtyOptions) {
var number = parseInt(dirtyNumber, 10)

if (unit === 'quarter') {
// many news outlets use "quý I"...
switch (number) {
case 1: return 'một'
case 2: return 'hai'
case 3: return 'ba'
case 4: return 'bốn'
case 1: return 'I'
case 2: return 'II'
case 3: return 'III'
case 4: return 'IV'
}
} else if (unit === 'dayOfWeek') {
// day of week in Vietnamese has ordinal number meaning, so we should use them
} else if (unit === 'day') {
// day of week in Vietnamese has ordinal number meaning,
// so we should use them, else it'll sound weird
switch (number) {
case 0: return 'CN'
case 1: return '2'
case 2: return '3'
case 3: return '4'
case 4: return '5'
case 5: return '6'
case 6: return '7'
case 1: return 'thứ 2' // meaning 2nd day but it's the first day of the week :D
case 2: return 'thứ 3' // meaning 3rd day
case 3: return 'thứ 4' // meaning 4th day and so on
case 4: return 'thứ 5'
case 5: return 'thứ 6'
case 6: return 'thứ 7'
case 7: return 'chủ nhật' // meaning Sunday, there's no 8th day :D
}
} else if (unit === 'week' || unit === 'isoWeek') {
} else if (unit === 'week') {
if (number === 1) {
return 'thứ nhất'
} else {
Expand All @@ -102,14 +172,40 @@ function ordinalNumber (dirtyNumber, dirtyOptions) {

var localize = {
ordinalNumber: ordinalNumber,
weekday: buildLocalizeFn(weekdayValues, 'long'),
weekdays: buildLocalizeArrayFn(weekdayValues, 'long'),
month: buildLocalizeFn(monthValues, 'long'),
months: buildLocalizeArrayFn(monthValues, 'long'),
timeOfDay: buildLocalizeFn(timeOfDayValues, 'long', function (hours) {
return (hours / 12) >= 1 ? 1 : 0

era: buildLocalizeFn({
values: eraValues,
defaultWidth: 'wide'
}),
timesOfDay: buildLocalizeArrayFn(timeOfDayValues, 'long')

quarter: buildLocalizeFn({
values: quarterValues,
defaultWidth: 'wide',
formattingValues: formattingQuarterValues,
defaultFormattingWidth: 'wide',
argumentCallback: function (quarter) {
return Number(quarter) - 1
}
}),

month: buildLocalizeFn({
values: monthValues,
defaultWidth: 'wide',
formattingValues: formattingMonthValues,
defaultFormattingWidth: 'wide'
}),

day: buildLocalizeFn({
values: dayValues,
defaultWidth: 'wide'
}),

dayPeriod: buildLocalizeFn({
values: dayPeriodValues,
defaultWidth: 'wide',
formattingValues: formattingDayPeriodValues,
defaulFormattingWidth: 'wide'
})
}

export default localize
Loading