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

fa-IR locale with tests plus 1 fix for gl locale #979

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
51 changes: 51 additions & 0 deletions src/locale/fa-IR/_lib/formatDistance/index.js
@@ -0,0 +1,51 @@
import utils from '../utils.js'

var formatDistanceLocale = {
lessThanXSeconds: 'کمتر از {{count}} ثانیه',

xSeconds: '{{count}} ثانیه',

halfAMinute: 'نیم دقیقه',

lessThanXMinutes: 'کمتر از {{count}} دقیقه',

xMinutes: '{{count}} دقیقه',

aboutXHours: 'نزدیک به {{count}} ساعت',

xHours: '{{count}} ساعت',

xDays: '{{count}} روز',

aboutXMonths: 'نزدیک به {{count}} ماه',

xMonths: '{{count}} ماه',

aboutXYears: 'نزدیک به {{count}} سال',

xYears: '{{count}} سال',

overXYears: 'بیش از {{count}} سال',

almostXYears: 'نزدیک به {{count}} سال'
}

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

var result
result = formatDistanceLocale[token].replace(
'{{count}}',
Number.isInteger(count) ? utils.eng2per(count) : ''
)

if (options.addSuffix) {
if (options.comparison > 0) {
return 'در ' + result
} else {
return result + ' پیش'
}
}

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

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

describe('fa-IR locale > formatDistance', function() {
describe('lessThanXSeconds', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('lessThanXSeconds', 1) === 'کمتر از ۱ ثانیه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('lessThanXSeconds', 2) === 'کمتر از ۲ ثانیه')
})
})
})

describe('xSeconds', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xSeconds', 1) === '۱ ثانیه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xSeconds', 2) === '۲ ثانیه')
})
})
})

describe('halfAMinute', function() {
it('returns a proper string', function() {
assert(formatDistance('halfAMinute') === 'نیم دقیقه')
})

it('ignores the second argument', function() {
assert(formatDistance('halfAMinute', 123) === 'نیم دقیقه')
})
})

describe('lessThanXMinutes', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('lessThanXMinutes', 1) === 'کمتر از ۱ دقیقه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('lessThanXMinutes', 2) === 'کمتر از ۲ دقیقه')
})
})
})

describe('xMinutes', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xMinutes', 1) === '۱ دقیقه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xMinutes', 2) === '۲ دقیقه')
})
})
})

describe('aboutXHours', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXHours', 1) === 'نزدیک به ۱ ساعت')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXHours', 2) === 'نزدیک به ۲ ساعت')
})
})
})

describe('xHours', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xHours', 1) === '۱ ساعت')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xHours', 2) === '۲ ساعت')
})
})
})

describe('xDays', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xDays', 1) === '۱ روز')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xDays', 2) === '۲ روز')
})
})
})

describe('aboutXMonths', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXMonths', 1) === 'نزدیک به ۱ ماه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXMonths', 2) === 'نزدیک به ۲ ماه')
})
})
})

describe('xMonths', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xMonths', 1) === '۱ ماه')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xMonths', 2) === '۲ ماه')
})
})
})

describe('aboutXYears', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXYears', 1) === 'نزدیک به ۱ سال')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('aboutXYears', 2) === 'نزدیک به ۲ سال')
})
})
})

describe('xYears', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xYears', 1) === '۱ سال')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xYears', 2) === '۲ سال')
})
})
})

describe('overXYears', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('overXYears', 1) === 'بیش از ۱ سال')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('overXYears', 2) === 'بیش از ۲ سال')
})
})
})

describe('almostXYears', function() {
context('when the count equals 1', function() {
it('returns a proper string', function() {
assert(formatDistance('almostXYears', 1) === 'نزدیک به ۱ سال')
})
})

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('almostXYears', 2) === 'نزدیک به ۲ سال')
})
})
})

context('with a past suffix', function() {
it('adds `ago` to a string', function() {
var result = formatDistance('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'نزدیک به ۱ سال پیش')
})
})

context('with a future suffix', function() {
it('adds `in` to a string', function() {
var result = formatDistance('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'در نیم دقیقه')
})
})
})
41 changes: 41 additions & 0 deletions src/locale/fa-IR/_lib/formatLong/index.js
@@ -0,0 +1,41 @@
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index.js'

var dateFormats = {
full: 'EEEE, MMMM do, y',
long: 'MMMM do, y',
medium: 'MMM d, y',
short: 'MM/dd/yyyy'
}

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

var dateTimeFormats = {
full: "{{date}} 'در ساعت' {{time}}",
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: 12 additions & 0 deletions src/locale/fa-IR/_lib/formatRelative/index.js
@@ -0,0 +1,12 @@
var formatRelativeLocale = {
lastWeek: "eeee 'گذشته،' 'ساعت' p",
yesterday: "'دیروز، ساعت' p",
today: "'امروز، ساعت' p",
tomorrow: "'فردا، ساعت' p",
nextWeek: "eeee'، ساعت' p",
other: 'P'
}

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