Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ce6924
commit 3514c08
Showing
9 changed files
with
1,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} |
Oops, something went wrong.