GuavaCZ / calendar

MIT License
140 stars 13 forks source link

[Bug]: Calendar will not render if app_locale is in country specific 'mode' #12

Closed sjardim closed 4 months ago

sjardim commented 4 months ago

What happened?

My APP_LOCALE is 'pt_PT'. This will throw a console error on the @event-calendar script:

index.js:682 Uncaught (in promise) RangeError: Incorrect locale information provided
    at new DateTimeFormat (<anonymous>)
    at index.js:682:24
    at m (index.js:150:19)
    at index.js:173:3
    at Object.subscribe (index.js:82:11)
    at s (utils.js:139:22)
    at index.js:158:4
    at Array.map (<anonymous>)
    at index.js:157:38
    at Object.subscribe (index.js:82:11)

The solution in my case was to add the $locale string prop to my project *calendar widget** class:

protected ?string $locale = 'pt';

I can PR to add this to the documentation if it's fine. Thanks!

How to reproduce the bug

Set .env APP_LOCALE to country-specific values such as 'pt_PT', 'fr_CA' etc.

Package Version

1.2

PHP Version

8.3

Laravel Version

11.14.0

Which operating systems does with happen with?

macOS

Notes

No response

lukas-frey commented 4 months ago

Hi, thanks for info. Maybe I can just take the first part of the locale when a country specific locale was provided. However I'm not sure if the "singular" locale code always has the same first part as the country specific locale code.

You're also welcome to PR it if you want.

sjardim commented 4 months ago

I'm 99% sure it's fine. This is a simple solution that can work alongside a mention in the docs of the $locale property and that's it. :)

Thank you Lukas for this awesome package! I'm exploring it for an app we are working on to help a company plan its maintenance services.

lukas-frey commented 4 months ago

Yes, I agree. It's released in v1.2.2. :)

I'm glad you enjoy the package. Sounds like a great use-case for the calendar, good luck with the app!