azuyalabs / yasumi

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

Translate bug #121

Closed projct1 closed 5 years ago

projct1 commented 5 years ago

Hello! I found strange bug! I make calendar! Translate works only with first holiday: http://skrinshoter.ru/s/031218/qrfDahGR In Russia.php provider all holidays are translated http://skrinshoter.ru/s/021218/7enYMBZO Here is simplified code:

$service = Yasumi::create('Russia', 2020, 'ru_RU');
$holidays = array_flip($service->getHolidayDates());
$period = new CarbonPeriod('2020-01-01', new CarbonInterval('P1D'), '2020-12-31');

foreach ($period as $month) {
    $date = $month->toDateString();

    if (array_key_exists($date, $holidays)) {
        echo $service->getHoliday($holidays[$date])->getName() . '<br>';
    }
}
stelgenhof commented 5 years ago

I've tried using your example but it is incomplete. (For example $this->holidayService and $date are not defined).

Can you maybe provide a standalone working example? That way I can better understand the issue.

Thanks! Sacha

projct1 commented 5 years ago

@stelgenhof Yea, sry... I edited first message, code works standalone now!

stelgenhof commented 5 years ago

@projct1 Thanks! Much better :) From what I can see, there is something wrong with the Russia Holiday Provider. Indeed only the first holiday is in the Russian language and the others not.

However if I try another country (e.g. Japan with the Japanese locale) then all holidays are translated correctly. Using your code with this change: $service = Yasumi::create('Japan', 2020, 'ja_JP') will render:

元日
成人の日
建国記念の日
春分の日
昭和の日
憲法記念日
みどりの日
こどもの日
振替休日 (憲法記念日)
海の日
体育の日
山の日
敬老の日
秋分の日
文化の日
勤労感謝の日
天皇誕生日

Not sure what the issue is, but let me investigate further.

Cheers! Sacha

projct1 commented 5 years ago

@stelgenhof Yea, investigate more plz, thanks 😄

stelgenhof commented 5 years ago

@projct1 Found the issue already... Except New Years day, all holidays for Russia don't have the locale parameter in place, which is needed for translation. Without that, Yasumi will use the fallback locale of 'en_US'.

I will make a fix for this.

Thanks for spotting this one!

projct1 commented 5 years ago

@stelgenhof Thanks dude) How i can update package?

stelgenhof commented 5 years ago

@projct1 It's not fixed yet...

stelgenhof commented 5 years ago

Issue has been fixed in the 'develop' branch.

projct1 commented 5 years ago

Ok, thanks =)