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 basic support for hu and lt localizations #864
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5bad878
add basic support for hu and lt localizations
bcdb8eb
Merge pull request #2 from pardoeryanair/localizations/lt_hu
izifortune 7a3cb6c
update version of lt and hu localizations
pardoeryanair 63c5fe9
Merge pull request #4 from pardoeryanair/localizations/localization-h…
izifortune c7abbae
Merge branch 'master' into master
kossnocorp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling that this could be improved somehow.
formatDistance
file doesn't has to have this exact structureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this is already merged 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leshakoss could you please elaborate what do you mean by that? Guys could improve in following PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case
formatDistanceLocale
object is not really needed because the logic is handled bytranslate
function below