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

Add Vietnamese locale #546

Merged
merged 4 commits into from Sep 1, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/locale/vi/_lib/formatDistance/index.js
@@ -0,0 +1,91 @@
var formatDistanceLocale = {
lessThanXSeconds: {
one: 'dưới 1 giây',
other: 'dưới {{count}} giây'
},

xSeconds: {
one: '1 giây',
other: '{{count}} giây'
},

halfAMinute: 'nửa phút',

lessThanXMinutes: {
one: 'dưới 1 phút',
other: 'dưới {{count}} phút'
},

xMinutes: {
one: '1 phút',
other: '{{count}} phút'
},

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

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

xDays: {
one: '1 ngày',
other: '{{count}} ngày'
},

aboutXMonths: {
one: 'khoảng 1 tháng',
other: 'khoảng {{count}} tháng'
},

xMonths: {
one: '1 tháng',
other: '{{count}} tháng'
},

aboutXYears: {
one: 'khoảng 1 năm',
other: 'khoảng {{count}} năm'
},

xYears: {
one: '1 năm',
other: '{{count}} năm'
},

overXYears: {
one: 'hơn 1 năm',
other: 'hơn {{count}} năm'
},

almostXYears: {
one: 'gần 1 năm',
other: 'gần {{count}} năm'
}
}

export default function formatDistance (token, count, options) {
options = options || {}

var result
if (typeof formatDistanceLocale[token] === 'string') {
result = formatDistanceLocale[token]
} else if (count === 1) {
result = formatDistanceLocale[token].one
} else {
result = formatDistanceLocale[token].other.replace('{{count}}', count)
}

if (options.addSuffix) {
if (options.comparison > 0) {
return result + ' nữa'
} else {
return result + ' trước'
}
}

return result
}
219 changes: 219 additions & 0 deletions src/locale/vi/_lib/formatDistance/test.js
@@ -0,0 +1,219 @@
// @flow
/* eslint-env mocha */

import assert from 'power-assert'
import formatDistance from '.'

describe('vi locale > formatDistance', function () {
describe('lessThanXSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 1) === 'dưới 1 giây')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 2) === 'dưới 2 giây')
})
})
})

describe('xSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xSeconds', 1) === '1 giây')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xSeconds', 2) === '2 giây')
})
})
})

describe('halfAMinute', function () {
it('returns a proper string', function () {
assert(formatDistance('halfAMinute') === 'nửa phút')
})

it('ignores the second argument', function () {
assert(formatDistance('halfAMinute', 123) === 'nửa phút')
})
})

describe('lessThanXMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 1) === 'dưới 1 phút')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 2) === 'dưới 2 phút')
})
})
})

describe('xMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMinutes', 1) === '1 phút')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMinutes', 2) === '2 phút')
})
})
})

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')
})
})

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

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

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

describe('xDays', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 1) === '1 ngày')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xDays', 2) === '2 ngày')
})
})
})

describe('aboutXMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 1) === 'khoảng 1 tháng')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 2) === 'khoảng 2 tháng')
})
})
})

describe('xMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMonths', 1) === '1 tháng')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xMonths', 2) === '2 tháng')
})
})
})

describe('aboutXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 1) === 'khoảng 1 năm')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 2) === 'khoảng 2 năm')
})
})
})

describe('xYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 1) === '1 năm')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('xYears', 2) === '2 năm')
})
})
})

describe('overXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 1) === 'hơn 1 năm')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 2) === 'hơn 2 năm')
})
})
})

describe('almostXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 1) === 'gần 1 năm')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 2) === 'gần 2 năm')
})
})
})

context('with a past suffix', function () {
it('adds `ago` to a string', function () {
var result = formatDistance('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'khoảng 1 năm trước')
})
})

context('with a future suffix', function () {
it('adds `in` to a string', function () {
var result = formatDistance('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'nửa phút nữa')
})
})
})
18 changes: 18 additions & 0 deletions src/locale/vi/_lib/formatLong/index.js
@@ -0,0 +1,18 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'

var formatLong = buildFormatLongFn({
// 23:25
LT: 'H:mm',
// 23:25:59
LTS: 'H:mm:ss',
// 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'
})

export default formatLong
12 changes: 12 additions & 0 deletions src/locale/vi/_lib/formatRelative/index.js
@@ -0,0 +1,12 @@
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'
}

export default function formatRelative (token, date, baseDate, options) {
return formatRelativeLocale[token]
}