Skip to content

Commit

Permalink
Merge pull request #16 from rsthegeek/master
Browse files Browse the repository at this point in the history
Added Persian language support
  • Loading branch information
aboudeh87 authored Feb 18, 2020
2 parents c89ea43 + 2213d89 commit adde6ad
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Date
/* allowed numbers values */
const ARABIC_NUMBERS = 0;
const INDIAN_NUMBERS = 1;
const PERSIAN_NUMBERS = 2;

/**
* @var string
Expand Down Expand Up @@ -175,6 +176,13 @@ class Date
*/
protected $arabicNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

/**
* Persian numbers
*
* @var array
*/
protected $persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];

/**
* @var Carbon
*/
Expand Down Expand Up @@ -350,6 +358,10 @@ public function format(string $format = null, int $numbers = null)
{
$dateString = str_replace($this->arabicNumbers, $this->indianNumbers, $dateString);
}
elseif ($numbers === static::PERSIAN_NUMBERS)
{
$dateString = str_replace($this->arabicNumbers, $this->persianNumbers, $dateString);
}

return $dateString;
}
Expand Down
96 changes: 96 additions & 0 deletions src/Translations/Persian.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace GeniusTS\HijriDate\Translations;


/**
* Class Persian
*
* @package GeniusTS\HijriDate\Translations
*/
class Persian implements TranslationInterface
{

/**
* Hijri Months names
*
* @var array
*/
protected $hijriMonths = [
'محرم',
'صفر',
'ربیع الاول',
'ربیع الثانی',
'جمادی الاول',
'جمادی الثانی',
'رجب',
'شعبان',
'رمضان',
'شوال',
'ذی القعده',
'ذی الحجه',
];

/**
* short days
*
* @var array
*/
protected $shortDays = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'];

/**
* days names
*
* @var array
*/
protected $days = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'];

/**
* periods
*
* @var array
*/
protected $periods = ['ق.ظ', 'ب.ظ'];

/**
* get array of months names
*
* @return array
*/
public function getHijriMonths(): array
{
return $this->hijriMonths;
}

/**
* get array of short days names
* started from Sunday
*
* @return array
*/
public function getShortDays(): array
{
return $this->shortDays;
}

/**
* get array of months names
* started from Sunday
*
* @return array
*/
public function getDays(): array
{
return $this->days;
}

/**
* get array of periods
*
* @return array
*/
public function getPeriods(): array
{
return $this->periods;
}
}

0 comments on commit adde6ad

Please sign in to comment.