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 locale (fa-IR) for v2 #1113

Merged
merged 2 commits into from Jun 4, 2019
Merged
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
1 change: 1 addition & 0 deletions src/esm/locale/index.js
Expand Up @@ -11,6 +11,7 @@ export { default as enUS } from './en-US/index.js'
export { default as eo } from './eo/index.js'
export { default as es } from './es/index.js'
export { default as et } from './et/index.js'
export { default as faIR } from './fa-IR/index.js'
export { default as fr } from './fr/index.js'
export { default as gl } from './gl/index.js'
export { default as he } from './he/index.js'
Expand Down
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: '1 ثانیه',
other: '{{count}} ثانیه'
},

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

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

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

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

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

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

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

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

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

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

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

almostXYears: {
one: 'نزدیک 1 سال',
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('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) === 'کمتر از 2 ثانیه')
})
})
})

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

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('xSeconds', 2) === '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) === 'کمتر از 2 دقیقه')
})
})
})

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

context('when the count is more than 1', function() {
it('returns a proper string', function() {
assert(formatDistance('almostXYears', 2) === 'نزدیک 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 === 'حدود 1 سال قبل')
})
})

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 do MMMM y',
long: 'do MMMM y',
medium: 'd MMM y',
short: 'yyyy/MM/dd'
}

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]
}