Skip to content

Commit adde6ad

Browse files
authored
Merge pull request #16 from rsthegeek/master
Added Persian language support
2 parents c89ea43 + 2213d89 commit adde6ad

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

src/Date.php

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Date
123123
/* allowed numbers values */
124124
const ARABIC_NUMBERS = 0;
125125
const INDIAN_NUMBERS = 1;
126+
const PERSIAN_NUMBERS = 2;
126127

127128
/**
128129
* @var string
@@ -175,6 +176,13 @@ class Date
175176
*/
176177
protected $arabicNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
177178

179+
/**
180+
* Persian numbers
181+
*
182+
* @var array
183+
*/
184+
protected $persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
185+
178186
/**
179187
* @var Carbon
180188
*/
@@ -350,6 +358,10 @@ public function format(string $format = null, int $numbers = null)
350358
{
351359
$dateString = str_replace($this->arabicNumbers, $this->indianNumbers, $dateString);
352360
}
361+
elseif ($numbers === static::PERSIAN_NUMBERS)
362+
{
363+
$dateString = str_replace($this->arabicNumbers, $this->persianNumbers, $dateString);
364+
}
353365

354366
return $dateString;
355367
}

src/Translations/Persian.php

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace GeniusTS\HijriDate\Translations;
4+
5+
6+
/**
7+
* Class Persian
8+
*
9+
* @package GeniusTS\HijriDate\Translations
10+
*/
11+
class Persian implements TranslationInterface
12+
{
13+
14+
/**
15+
* Hijri Months names
16+
*
17+
* @var array
18+
*/
19+
protected $hijriMonths = [
20+
'محرم',
21+
'صفر',
22+
'ربیع الاول',
23+
'ربیع الثانی',
24+
'جمادی الاول',
25+
'جمادی الثانی',
26+
'رجب',
27+
'شعبان',
28+
'رمضان',
29+
'شوال',
30+
'ذی القعده',
31+
'ذی الحجه',
32+
];
33+
34+
/**
35+
* short days
36+
*
37+
* @var array
38+
*/
39+
protected $shortDays = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'];
40+
41+
/**
42+
* days names
43+
*
44+
* @var array
45+
*/
46+
protected $days = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'];
47+
48+
/**
49+
* periods
50+
*
51+
* @var array
52+
*/
53+
protected $periods = ['ق.ظ', 'ب.ظ'];
54+
55+
/**
56+
* get array of months names
57+
*
58+
* @return array
59+
*/
60+
public function getHijriMonths(): array
61+
{
62+
return $this->hijriMonths;
63+
}
64+
65+
/**
66+
* get array of short days names
67+
* started from Sunday
68+
*
69+
* @return array
70+
*/
71+
public function getShortDays(): array
72+
{
73+
return $this->shortDays;
74+
}
75+
76+
/**
77+
* get array of months names
78+
* started from Sunday
79+
*
80+
* @return array
81+
*/
82+
public function getDays(): array
83+
{
84+
return $this->days;
85+
}
86+
87+
/**
88+
* get array of periods
89+
*
90+
* @return array
91+
*/
92+
public function getPeriods(): array
93+
{
94+
return $this->periods;
95+
}
96+
}

0 commit comments

Comments
 (0)