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

[php] Add bulgarian v1.33.0 #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ echo $m->format('[Wochentag:] l'); // e.g. Wochentag: Mittwoch
__Supported languages so far:__

```ar_TN``` Arabic (Tunisia)
```bg_BG``` Bulgarian
```ca_ES``` Catalan
```cs_CZ``` Czech
```da_DK``` Danish
Expand Down Expand Up @@ -434,6 +435,7 @@ You can now run through the result and put it formatted into a drop-down field o
- added:
- support for PHP 8.2 [#218](https://github.com/fightbulc/moment.php/pull/218)
- support for PHP 8.3 [#227](https://github.com/fightbulc/moment.php/pull/227)
- Bulgarian locale [#206](https://github.com/fightbulc/moment.php/pull/206)

### 1.33.0
- fixed:
Expand Down
75 changes: 75 additions & 0 deletions src/Locales/bg_BG.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

// locale: bulgarian (bg)
// author: JamesAxl https://github.com/jamesaxl

return array(
"months" => explode('_', 'януари_февруари_март_април_май_юни_юли_август_септември_октомври_ноември_декември'),
"monthsShort" => explode('_', 'яну_фев_мар_апр_май_юни_юли_авг_сеп_окт_ное_дек'),
"weekdays" => explode('_', 'понеделник_вторник_сряда_четвъртък_петък_събота_неделя'),
"weekdaysShort" => explode('_', 'пон_вто_сря_чет_пет_съб_нед'),
"calendar" => array(
"sameDay" => '[Днес]',
"nextDay" => '[Утре]',
"lastDay" => '[Вчера]',
"lastWeek" => 'l',
"sameElse" => 'l',
"withTime" => '[в] H:i',
"default" => 'd/m/Y',
),

"relativeTime" => array(
"future" => 'след %s',
"past" => 'преди %s',
"s" => 'няколко секунди',
"ss" => '%d секунди',
"m" => 'минута',
"mm" => '%d минути',
"h" => 'час',
"hh" => '%d часа',
"d" => 'ден',
"dd" => '%d дена',
"M" => 'месец',
"MM" => '%d месеца',
"y" => 'година',
"yy" => '%d години',
),

"ordinal" => function ($number)
{
$lastDigit = $number % 10;
$lastTwoDigits = $number % 100;

if ($number === 0) {
return $number . '-ев';
} else if ($lastTwoDigits === 0) {
return $number . '-ен';
} else if ($lastTwoDigits > 10 && $lastTwoDigits < 20) {
return $number . '-ти';
} else if ($lastDigit === 1) {
return $number . '-ви';
} else if ($lastDigit === 2) {
return $number . '-ри';
} else if ($lastDigit === 7 || $lastDigit === 8) {
return $number . '-ми';
} else {
return $number . '-ти';
}
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 7 // The week that contains Jan 7th is the first week of the year
),
"customFormats" => array(
"LTS" => "G:i:s",
"LT" => "G:i", // 20:30
"L" => "d/m/Y", // 04/09/1986
"l" => "j/n/Y", // 4/9/1986
"LL" => "jS F Y", // 4 Septembre 1986
"ll" => "j M Y", // 4 Sep 1986
"LLL" => "jS F Y G:i", // 4 Septembre 1986 20:30
"lll" => "j M Y G:i", // 4 Sep 1986 20:30
"LLLL" => "l, jS F Y G:i", // Jeudi, 4 Septembre 1986 20:30
"llll" => "D, j M Y G:i", // Jeu, 4 Sep 1986 20:30
),
);
97 changes: 97 additions & 0 deletions tests/Unit/MomentBulgarianLocaleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Moment\Test\Unit;

use Moment\Moment;
use PHPUnit\Framework;

final class MomentBulgarianLocaleTest extends Framework\TestCase
{
protected function setUp(): void
{
Moment::setLocale('bg_BG');
}

public function testWeekdayNames()
{
$startingDate = '2015-01-04T00:00:00+0000';

$moment = new Moment($startingDate);

$weekdayNames = array(
1 => array('пон', 'понеделник'),
2 => array('вто', 'вторник'),
3 => array('сря', 'сряда'),
4 => array('чет', 'четвъртък'),
5 => array('пет', 'петък'),
6 => array('съб', 'събота'),
7 => array('нед', 'неделя'),
);

for ($d = 1; $d < 7; $d++)
{
self::assertEquals($weekdayNames[$moment->getWeekday()][0], $moment->getWeekdayNameShort(), 'weekday short name failed');
self::assertEquals($weekdayNames[$moment->getWeekday()][1], $moment->getWeekdayNameLong(), 'weekday long name failed');

$moment->addDays(1);
}
}

public function testMonthNames()
{
$startingDate = '2015-01-04T00:00:00+0000';

$moment = new Moment($startingDate);

$monthNames = array(
1 => array('яну', 'януари'),
2 => array('фев', 'февруари'),
3 => array('мар', 'март'),
4 => array('апр', 'април'),
5 => array('май', 'май'),
6 => array('юни', 'юни'),
7 => array('юли', 'юли'),
8 => array('авг', 'август'),
9 => array('сеп', 'септември'),
10 => array('окт', 'октомври'),
11 => array('ное', 'ноември'),
12 => array('дек', 'декември'),
);

for ($d = 1; $d < 12; $d++)
{
self::assertEquals($monthNames[$moment->format('n')][0], $moment->getMonthNameShort(), 'month short name failed');
self::assertEquals($monthNames[$moment->format('n')][1], $moment->getMonthNameLong(), 'month long name failed');

$moment->addMonths(1);
}
}

public function testFormat()
{
$values = array(
array('l, F d Y, g:i:s a', 'неделя, февруари 14 2010, 3:25:50 pm'),
array('D, gA', 'нед, 3PM'),
array('n m F M', '2 02 февруари фев'),
array('Y y', '2010 10'),
array('j d', '14 14'),
array('[the] z [day of the year]', 'the 44 day of the year')
);

$moment = new Moment('2010-02-14 15:25:50');

for ($i = 0; $i < count($values); $i++) {
self::assertEquals($values[$i][1], $moment->format($values[$i][0]));
}
}

public function testRelative()
{
$begin = new Moment('2015-06-14 20:46:22', 'Europe/Berlin');

$end = new Moment('2015-06-14 20:48:32', 'Europe/Berlin');

self::assertEquals('след 2 минути', $end->from($begin)->getRelative());
self::assertEquals('преди 2 минути', $begin->from($end)->getRelative());
}
}