azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.04k stars 152 forks source link

Localized names #37

Closed johlton closed 8 years ago

johlton commented 8 years ago

Using this great library in Laravel 5.3 i cannot get the localized names to work (in my case German).

Calling: $holidays = Yasumi::create('Germany', Carbon::now()->year, 'de_DE');

foreach ($holidays->getHolidayNames() as $name) {
    echo $name . PHP_EOL;
}

Result:

newYearsDay
goodFriday
...

The locale is set correctly. I'm surely missing something obvious here but can you point me to the right direction?

Thanks!

stelgenhof commented 8 years ago

Thanks! I don't have a L5.3 environment at hand, so let me test this tomorrow. I actually haven't tested this with any particular framework, however should indeed work.

stelgenhof commented 8 years ago

Hi @johlton

Just checked and the function getHolidayNames() only returns the short names of the holidays. If you use the function getHolidays() you can get the localized names, like this:

$holidays = Yasumi::create('Germany', 2016, 'de_DE');
foreach ($holidays->getHolidays() as $name) {
    echo $name->getName().PHP_EOL;
}

Result:

Neujahr
Karfreitag
Easter Sunday
Ostermontag
Tag der Arbeit
Christi Himmelfahrt
Whitsunday
Pfingstmontag
Tag der Deutschen Einheit
1. Weihnachtsfeiertag
2. Weihnachtsfeiertag

I admit the function name getHolidayNames() is a bit misleading :). The advantage of the getHolidays() function is that it returns a collection of Holiday objects, so you also can access other object properties!

Let me know if this works for you.

johlton commented 8 years ago

Thank you so much, it works like a charm. Keep up the great work! :)