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 Persian language with code fa-IR #903

Closed
wants to merge 3 commits into from
Closed
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/fa-IR/_lib/formatDistance/index.js
@@ -0,0 +1,91 @@
var formatDistanceLocale = {
lessThanXSeconds: {
one: 'کمتر از یک ثانیه',
other: 'کم تر از {{count}} ثانیه'
},

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

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

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

xMinutes: {
one: '۱ دقیقه',
other: '{{count}} دقیقه'
},

aboutXHours: {
one: 'حدود ۱ ساعت',
other: 'حدود {{count}} ساعت'
},

xHours: {
one: '۱ ساعت',
other: '{{count}} ساعت'
},

xDays: {
one: '۱ روز',
other: '{{count}} روز'
},

aboutXMonths: {
one: 'حدود یک ماه',
other: 'حدود {{count}} یک ماه'
},

xMonths: {
one: '۱ ماه',
other: '{{count}} ماه'
},

aboutXYears: {
one: 'حدود یک سال',
other: 'حدود {{count}} سال'
},

xYears: {
one: 'یک سال',
other: '{{count}} سال'
},

overXYears: {
one: 'بیشتر از ۱ سال',
other: 'بیشتر از {{count}} سال'
},

almostXYears: {
one: 'تقریبا ۱ سال',
other: 'تقریبا {{count}} سال'
}
}

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
} 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('en-US locale > formatDistance', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the description

describe('lessThanXSeconds', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 1) === 'less than a second')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXSeconds', 2) === 'less than 2 seconds')
})
})
})

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

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

describe('halfAMinute', function () {
it('returns a proper string', function () {
assert(formatDistance('halfAMinute') === 'half a minute')
})

it('ignores the second argument', function () {
assert(formatDistance('halfAMinute', 123) === 'half a minute')
})
})

describe('lessThanXMinutes', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 1) === 'less than a minute')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('lessThanXMinutes', 2) === 'less than 2 minutes')
})
})
})

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

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

describe('aboutXHours', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 1) === 'about 1 hour')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXHours', 2) === 'about 2 hours')
})
})
})

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

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

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

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

describe('aboutXMonths', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 1) === 'about 1 month')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXMonths', 2) === 'about 2 months')
})
})
})

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

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

describe('aboutXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 1) === 'about 1 year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('aboutXYears', 2) === 'about 2 years')
})
})
})

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

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

describe('overXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 1) === 'over 1 year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('overXYears', 2) === 'over 2 years')
})
})
})

describe('almostXYears', function () {
context('when the count equals 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 1) === 'almost 1 year')
})
})

context('when the count is more than 1', function () {
it('returns a proper string', function () {
assert(formatDistance('almostXYears', 2) === 'almost 2 years')
})
})
})

context('with a past suffix', function () {
it('adds `ago` to a string', function () {
var result = formatDistance('aboutXYears', 1, {
addSuffix: true,
comparison: -1
})
assert(result === 'about 1 year ago')
})
})

context('with a future suffix', function () {
it('adds `in` to a string', function () {
var result = formatDistance('halfAMinute', null, {
addSuffix: true,
comparison: 1
})
assert(result === 'in half a minute')
})
})
})
Copy link
Member

@kossnocorp kossnocorp Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests aren't implemented.

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: "'دیروز at' p",
today: "'امروز در' p",
tomorrow: "'فردا در' p",
nextWeek: "eeee 'در' p",
other: 'P'
}

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