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

Add support for multi languages #177

Merged
merged 9 commits into from
Jan 24, 2024
Merged

Add support for multi languages #177

merged 9 commits into from
Jan 24, 2024

Conversation

Nielsvanpach
Copy link
Member

No description provided.

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

tests/HolidaysTest.php Outdated Show resolved Hide resolved
@Nielsvanpach Nielsvanpach merged commit 93bd4f6 into main Jan 24, 2024
16 checks passed
@Nielsvanpach Nielsvanpach deleted the feature/localization branch January 24, 2024 12:12
@herpaderpaldent
Copy link

Thank you for this addition. This will help certainly!

However i have one question:

The current solution with language works via the 'magic' method but not if you would create the Country Object as you would do in the current README.

holidays/README.md

Lines 119 to 148 in faf22be

## Adding a new country
1. Create a new class in the `Countries` directory. It should extend the `Country` class.
2. Add a test for the new country in the `tests` directory.
3. Run the tests so a snapshot gets created.
4. Verify the result in the newly created snapshot is correct.
5. If the country has multiple languages, add a file in the `lang/` directory.
In case your country has specific rules for calculating holidays,
for example region specific holidays, you can pass this to the constructor of your country class.
```php
$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get();
```
The value, `de-bw`, will be passed to the region parameter of the constructor of a country.
```php
class Austria extends Country
{
protected function __construct(
protected ?string $region = null,
) {
}
protected function allHolidays(int $year): array
{
// Here you can use $this->region (or other variables) to calculate holidays
}
```

This might be because

public static function make(): static

does not accept named parameters. Are you open to accept named parameter in that method and drop ...func_get_args() as well?

Or is the construction of holidays via the magic method the standard?

@Nielsvanpach
Copy link
Member Author

I'm not sure I understand what you mean. Could you add a PR with a failing test?

I've included a test on how to use this with named params:
https://github.com/spatie/holidays/pull/177/files#diff-198ea683244cb0b1bcd6bc0093bf6a397a011ee9dcbbaca1e15917f6acbf54bcR96

herpaderpaldent added a commit to herpaderpaldent/holidays that referenced this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants