Skip to content

Commit

Permalink
fix: add fallback for locales with country code
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <[email protected]>
  • Loading branch information
lukas-frey committed Jul 23, 2024
1 parent 2e48edc commit 22d1441
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,17 @@ public function getNoEventsClickContextMenuActions(): array

https://github.com/user-attachments/assets/7c2537d5-8acf-459f-a9a8-be02d4018448

## Customization
### Locale
By default, the calendar will use the app's locale.

The underlying calendar package doesn't support locales as a combination of language and region/country code, so locales such as `fr_CA` or `en_US` become invalid.

We attempt to resolve this by only using the first language part of the locale. If you still run into any issues with the localization, you can override the calendar's locale manually using the `locale` property:

```php
protected ?string $locale = 'en';
```

## Troubleshooting
### Context menu actions don't work
Expand Down
10 changes: 9 additions & 1 deletion src/Concerns/HasLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public function locale(string $locale): static

public function getLocale(): string
{
return $this->evaluate($this->locale) ?? app()->getLocale();
return $this->evaluate($this->locale) ?? $this->getDefaultLocale();
}

private function getDefaultLocale(): string
{
return str(app()->getLocale())
->before('_')
->toString()
;
}
}

0 comments on commit 22d1441

Please sign in to comment.