Skip to content

Commit 85923cd

Browse files
committed
Use persian numerals for farsi language strings
1 parent 7e57aac commit 85923cd

File tree

7 files changed

+2395
-3052
lines changed

7 files changed

+2395
-3052
lines changed

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### v7.0.0
4+
- Use Intl to render persian number for farsi languages
5+
- Looking for help testing the results and then doing the same for Arabic
6+
37
#### v7.0.0
48
- Added support for React 18
59
- Added hi.js language strings
@@ -8,13 +12,6 @@
812
- Update ru.js language strings
913
- Fix memory leak
1014
- Update dependencies
11-
- Bump ansi-regex from 5.0.0 to 5.0.1
12-
- Bump ansi-regex from 5.0.0 to 5.0.1
13-
- Bump minimist from 1.2.5 to 1.2.6
14-
- Bump minimist from 1.2.5 to 1.2.6
15-
- Bump path-parse from 1.0.6 to 1.0.7
16-
- Bump tmpl from 1.0.4 to 1.0.5
17-
- Bump tmpl from 1.0.4 to 1.0.5
1815

1916
#### v6.1.0
2017
- Added `eslint-plugin-react-hooks` and fixed the dependencies for hooks used in the library.

package.json

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-timeago",
3-
"version": "7.0.0",
3+
"version": "7.1.0",
44
"description": "A simple Time-Ago component for ReactJs",
55
"main": "lib/index.js",
66
"module": "es6/index.js",
@@ -14,6 +14,9 @@
1414
"prepublish": "npm run build",
1515
"test": "jest --coverage"
1616
},
17+
"jest": {
18+
"testEnvironment": "jsdom"
19+
},
1720
"repository": {
1821
"type": "git",
1922
"url": "https://github.com/naman34/react-timeago.git"
@@ -36,36 +39,37 @@
3639
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
3740
},
3841
"devDependencies": {
39-
"@babel/cli": "^7.13.16",
40-
"@babel/core": "^7.14.2",
41-
"@babel/eslint-parser": "^7.14.2",
42-
"@babel/plugin-syntax-flow": "^7.12.13",
43-
"@babel/plugin-syntax-jsx": "^7.12.13",
44-
"@babel/plugin-transform-flow-strip-types": "^7.13.0",
45-
"@babel/plugin-transform-react-jsx": "^7.13.12",
46-
"@babel/preset-env": "^7.14.2",
47-
"@babel/preset-flow": "^7.13.13",
48-
"@babel/preset-react": "^7.13.13",
42+
"@babel/cli": "^7.17.10",
43+
"@babel/core": "^7.18.2",
44+
"@babel/eslint-parser": "^7.18.2",
45+
"@babel/plugin-syntax-flow": "^7.17.12",
46+
"@babel/plugin-syntax-jsx": "^7.17.12",
47+
"@babel/plugin-transform-flow-strip-types": "^7.17.12",
48+
"@babel/plugin-transform-react-jsx": "^7.17.12",
49+
"@babel/preset-env": "^7.18.2",
50+
"@babel/preset-flow": "^7.17.12",
51+
"@babel/preset-react": "^7.17.12",
4952
"@babel/preset-stage-1": "^7.8.3",
50-
"@rollup/plugin-babel": "^5.3.0",
51-
"@rollup/plugin-commonjs": "^19.0.0",
52-
"@rollup/plugin-node-resolve": "^13.0.0",
53-
"@rollup/plugin-replace": "^2.4.2",
54-
"@testing-library/jest-dom": "^5.11.4",
55-
"@testing-library/react": "^11.0.4",
56-
"babel-jest": "^26.3.0",
57-
"eslint": "^7.26.0",
58-
"eslint-config-prettier": "^8.3.0",
59-
"eslint-plugin-flowtype": "^5.7.2",
60-
"eslint-plugin-import": "^2.23.2",
61-
"eslint-plugin-react-hooks": "^4.2.0",
62-
"flow-bin": "^0.151.0",
63-
"jest": "^26.4.2",
64-
"prettier": "^2.3.0",
65-
"react": "^17.0.2",
53+
"@rollup/plugin-babel": "^5.3.1",
54+
"@rollup/plugin-commonjs": "^22.0.0",
55+
"@rollup/plugin-node-resolve": "^13.3.0",
56+
"@rollup/plugin-replace": "^4.0.0",
57+
"@testing-library/jest-dom": "^5.16.4",
58+
"@testing-library/react": "^13.3.0",
59+
"babel-jest": "^28.1.1",
60+
"eslint": "^8.17.0",
61+
"eslint-config-prettier": "^8.5.0",
62+
"eslint-plugin-flowtype": "^8.0.3",
63+
"eslint-plugin-import": "^2.26.0",
64+
"eslint-plugin-react-hooks": "^4.5.0",
65+
"flow-bin": "^0.180.0",
66+
"jest": "^28.1.1",
67+
"jest-environment-jsdom": "^28.1.1",
68+
"prettier": "^2.6.2",
69+
"react": "^18.1.0",
6670
"react-addons-test-utils": "^15.6.2",
67-
"react-dom": "^17.0.2",
68-
"rollup": "^2.48.0"
71+
"react-dom": "^18.1.0",
72+
"rollup": "^2.75.6"
6973
},
7074
"dependencies": {},
7175
"prettier": {

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ export default function TimeAgo({
6565
minPeriod = 0,
6666
maxPeriod = WEEK,
6767
title,
68-
now = Date.now,
68+
now = () => Date.now(),
6969
...passDownProps
7070
}: Props): null | React.MixedElement {
7171
const [timeNow, setTimeNow] = useState(now())
7272
useEffect(() => {
7373
if (!live) {
7474
return
7575
}
76-
const tick = (): number => {
76+
const tick = (): 0 | TimeoutID => {
7777
const then = dateParser(date).valueOf()
7878
if (!then) {
7979
console.warn('[react-timeago] Invalid Date provided')

src/language-strings/fa-short.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
11
/* @flow */
22
import type { L10nsStrings } from '../formatters/buildFormatter'
33

4+
const hasIntl = typeof Intl !== 'undefined' && Intl.NumberFormat != null
5+
46
// persion shortened
57
const strings: L10nsStrings = {
68
prefixAgo: null,
79
prefixFromNow: null,
810
suffixAgo: '',
911
suffixFromNow: '',
10-
seconds: '1دقیقه',
11-
minute: '1دقیقه',
12-
minutes: '%dدقیقه',
13-
hour: '1ساعت',
14-
hours: '%dساعت',
15-
day: '1روز',
16-
days: '%dروز',
17-
month: '1ماه',
18-
months: '%dماه',
19-
year: '1سال',
20-
years: '%dسال',
12+
seconds: '۱دقیقه',
13+
minute: '۱دقیقه',
14+
minutes: (value) => {
15+
if (hasIntl) {
16+
return new Intl.NumberFormat('fa').format(value) + 'دقیقه'
17+
}
18+
return '%dدقیقه'
19+
},
20+
hour: '۱ساعت',
21+
hours: (value) => {
22+
if (hasIntl) {
23+
return new Intl.NumberFormat('fa').format(value) + 'ساعت'
24+
}
25+
return '%dساعت'
26+
},
27+
day: '۱روز',
28+
days: (value) => {
29+
if (hasIntl) {
30+
return new Intl.NumberFormat('fa').format(value) + 'روز'
31+
}
32+
return '%dروز'
33+
},
34+
month: '۱ماه',
35+
months: (value) => {
36+
if (hasIntl) {
37+
return new Intl.NumberFormat('fa').format(value) + 'ماه'
38+
}
39+
return '%dماه'
40+
},
41+
year: '۱سال',
42+
years: (value) => {
43+
if (hasIntl) {
44+
return new Intl.NumberFormat('fa').format(value) + 'سال'
45+
}
46+
return '%dسال'
47+
},
2148
wordSeparator: ' ',
2249
}
2350

src/language-strings/fa.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* @flow */
22
import type { L10nsStrings } from '../formatters/buildFormatter'
33

4+
const hasIntl = typeof Intl !== 'undefined' && Intl.NumberFormat != null
5+
46
// Persian
57
// Use DIR attribute for RTL text in Persian Language for ABBR tag .
68
// By MB.seifollahi@gmail.com
@@ -11,15 +13,43 @@ const strings: L10nsStrings = {
1113
suffixFromNow: 'از حال',
1214
seconds: 'کمتر از یک دقیقه',
1315
minute: 'حدود یک دقیقه',
14-
minutes: '%d دقیقه',
16+
minutes: (value) => {
17+
if (hasIntl) {
18+
return new Intl.NumberFormat('fa').format(value) + ' دقیقه'
19+
}
20+
return '%d دقیقه'
21+
},
1522
hour: 'حدود یک ساعت',
16-
hours: 'حدود %d ساعت',
23+
hours: (value) => {
24+
if (hasIntl) {
25+
return 'حدود %d ساعت'.replace(
26+
'%d',
27+
new Intl.NumberFormat('fa').format(value),
28+
)
29+
}
30+
return 'حدود %d ساعت'
31+
},
1732
day: 'یک روز',
18-
days: '%d روز',
33+
days: (value) => {
34+
if (hasIntl) {
35+
return '%d روز'.replace('%d', new Intl.NumberFormat('fa').format(value))
36+
}
37+
return '%d روز'
38+
},
1939
month: 'حدود یک ماه',
20-
months: '%d ماه',
40+
months: (value) => {
41+
if (hasIntl) {
42+
return '%d ماه'.replace('%d', new Intl.NumberFormat('fa').format(value))
43+
}
44+
return '%d ماه'
45+
},
2146
year: 'حدود یک سال',
22-
years: '%d سال',
47+
years: (value) => {
48+
if (hasIntl) {
49+
return '%d سال'.replace('%d', new Intl.NumberFormat('fa').format(value))
50+
}
51+
return '%d سال'
52+
},
2353
wordSeparator: ' ',
2454
}
2555

src/language-strings/uz.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ const strings: L10nsStrings = {
99
suffixFromNow: null,
1010
seconds: 'bir necha soniya',
1111
minute: '1 daqiqa',
12-
minutes: function (_value) {
13-
return '%d daqiqa'
14-
},
12+
minutes: '%d daqiqa',
1513
hour: '1 soat',
16-
hours: function (_value) {
17-
return '%d soat'
18-
},
14+
hours: '%d soat',
1915
day: '1 kun',
20-
days: function (_value) {
21-
return '%d kun'
22-
},
16+
days: '%d kun',
2317
month: '1 oy',
24-
months: function (_value) {
25-
return '%d oy'
26-
},
18+
months: '%d oy',
2719
year: '1 yil',
28-
years: function (_value) {
29-
return '%d yil'
30-
},
20+
years: '%d yil',
3121
wordSeparator: ' ',
3222
}
3323

0 commit comments

Comments
 (0)