Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
973d137
commit a5420d6
Showing
24 changed files
with
2,459 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
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,135 @@ | ||
var formatDistanceLocale = { | ||
lessThanXSeconds: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xSeconds: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
halfAMinute: 'fél perce', | ||
|
||
lessThanXMinutes: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xMinutes: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
aboutXHours: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xHours: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xDays: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
aboutXMonths: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xMonths: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
aboutXYears: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
xYears: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
overXYears: { | ||
one: translate, | ||
other: translate | ||
}, | ||
|
||
almostXYears: { | ||
one: translate, | ||
other: translate | ||
} | ||
} | ||
|
||
var translations = { | ||
'about': 'körülbelül', | ||
'over': 'több mint', | ||
'almost': 'majdnem', | ||
'lessthan': 'kevesebb, mint' | ||
} | ||
|
||
function translate (number, addSuffix, key, isFuture) { | ||
var num = number | ||
switch (key) { | ||
case 'xseconds_one': | ||
return (isFuture || !addSuffix) ? 'néhány másodperc' : 'néhány másodperce' | ||
case 'xseconds_other': | ||
return num + ((isFuture || !addSuffix) ? ' másodperc' : ' másodperce') | ||
case 'xminutes_one': | ||
return 'egy' + (isFuture || !addSuffix ? ' perc' : ' perce') | ||
case 'xminutes_other': | ||
return num + ((isFuture || !addSuffix ? ' perc' : ' perce')) | ||
case 'xhours_one': | ||
return 'egy' + (isFuture || !addSuffix ? ' óra' : ' órája') | ||
case 'xhours_other': | ||
return num + ((isFuture || !addSuffix ? ' óra' : ' órája')) | ||
case 'xdays_one': | ||
return 'egy' + (isFuture || !addSuffix ? ' nap' : ' napja') | ||
case 'xdays_other': | ||
return num + ((isFuture || !addSuffix ? ' nap' : ' napja')) | ||
case 'xmonths_one': | ||
return 'egy' + (isFuture || !addSuffix ? ' hónap' : ' hónapja') | ||
case 'xmonths_other': | ||
return num + ((isFuture || !addSuffix ? ' hónap' : ' hónapja')) | ||
case 'xyears_one': | ||
return 'egy' + (isFuture || !addSuffix ? ' év' : ' éve') | ||
case 'xyears_other': | ||
return num + ((isFuture || !addSuffix ? ' év' : ' éve')) | ||
} | ||
return '' | ||
} | ||
|
||
export default function formatDistance (token, count, options) { | ||
options = options || {} | ||
var adverb = token.match(/about|over|almost|lessthan/i) | ||
var unit = token.replace(adverb, '') | ||
|
||
var result | ||
if (typeof formatDistanceLocale[token] === 'string') { | ||
result = formatDistanceLocale[token] | ||
} else if (count === 1) { | ||
result = formatDistanceLocale[token].one(count, options.addSuffix, unit.toLowerCase() + '_one', options.comparison > 0) | ||
} else { | ||
result = formatDistanceLocale[token].other(count, options.addSuffix, unit.toLowerCase() + '_other', options.comparison > 0) | ||
} | ||
|
||
if (adverb) { | ||
result = translations[adverb[0].toLowerCase()] + ' ' + result | ||
} | ||
|
||
if (options.addSuffix) { | ||
if (options.comparison > 0) { | ||
return result + ' múlva' | ||
} else { | ||
return result + ' ezelőtt' | ||
} | ||
} | ||
|
||
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('hu locale > formatDistance', function () { | ||
describe('lessThanXSeconds', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXSeconds', 1) === 'kevesebb, mint néhány másodperc') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXSeconds', 2) === 'kevesebb, mint 2 másodperc') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xSeconds', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xSeconds', 1) === 'néhány másodperc') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xSeconds', 2) === '2 másodperc') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('halfAMinute', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('halfAMinute') === 'fél perce') | ||
}) | ||
|
||
it('ignores the second argument', function () { | ||
assert(formatDistance('halfAMinute', 123) === 'fél perce') | ||
}) | ||
}) | ||
|
||
describe('lessThanXMinutes', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXMinutes', 1) === 'kevesebb, mint egy perc') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('lessThanXMinutes', 2) === 'kevesebb, mint 2 perc') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMinutes', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMinutes', 1) === 'egy perc') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMinutes', 2) === '2 perc') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXHours', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXHours', 1) === 'körülbelül egy óra') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXHours', 2) === 'körülbelül 2 óra') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xHours', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xHours', 1) === 'egy óra') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xHours', 2) === '2 óra') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xDays', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xDays', 1) === 'egy nap') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xDays', 2) === '2 nap') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXMonths', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXMonths', 1) === 'körülbelül egy hónap') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXMonths', 2) === 'körülbelül 2 hónap') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xMonths', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMonths', 1) === 'egy hónap') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xMonths', 2) === '2 hónap') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('aboutXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXYears', 1) === 'körülbelül egy év') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('aboutXYears', 2) === 'körülbelül 2 év') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('xYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xYears', 1) === 'egy év') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('xYears', 2) === '2 év') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('overXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('overXYears', 1) === 'több mint egy év') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('overXYears', 2) === 'több mint 2 év') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('almostXYears', function () { | ||
context('when the count equals 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('almostXYears', 1) === 'majdnem egy év') | ||
}) | ||
}) | ||
|
||
context('when the count is more than 1', function () { | ||
it('returns a proper string', function () { | ||
assert(formatDistance('almostXYears', 2) === 'majdnem 2 év') | ||
}) | ||
}) | ||
}) | ||
|
||
context('with a past suffix', function () { | ||
it('adds `ezelőtt` to a string', function () { | ||
var result = formatDistance('aboutXYears', 1, { | ||
addSuffix: true, | ||
comparison: -1 | ||
}) | ||
assert(result === 'körülbelül egy éve ezelőtt') | ||
}) | ||
}) | ||
|
||
context('with a future suffix', function () { | ||
it('adds `múlva` to a string', function () { | ||
var result = formatDistance('halfAMinute', null, { | ||
addSuffix: true, | ||
comparison: 1 | ||
}) | ||
assert(result === 'fél perce múlva') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.