Skip to content

Commit

Permalink
use native translation
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent committed Jan 24, 2024
1 parent 92ab6ef commit f866e82
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 53 deletions.
16 changes: 16 additions & 0 deletions lang/switzerland/de/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"New Year's Day" : "Neujahrstag",
"Berchtold's Day" : "Berchtoldstag",
"St. Joseph's Day" : "Josefstag",
"Good Friday" : "Karfreitag",
"Easter Monday" : "Ostermontag",
"Ascension Day" : "Auffahrt",
"Whit Monday" : "Pfingstmontag",
"Corpus Christi" : "Fronleichnam",
"Swiss National Day" : "Bundesfeier",
"Assumption Day" : "Mariä Himmelfahrt",
"All Saints' Day" : "Allerheiligen",
"Immaculate Conception" : "Mariä Empfängnis",
"Christmas Day" : "Weihnachtstag",
"St. Stephen's Day" : "Stephanstag"
}
16 changes: 16 additions & 0 deletions lang/switzerland/fr/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"New Year's Day": "Nouvel an",
"Berchtold's Day": "2 janvier",
"St. Joseph's Day": "Saint-Joseph",
"Good Friday": "Vendredi saint",
"Easter Monday": "Lundi de Pâques",
"Ascension Day": "Ascension",
"Whit Monday": "Lundi de Pentecôte",
"Corpus Christi": "Fête-Dieu",
"Swiss National Day": "Fête nationale",
"Assumption Day": "Assomption",
"All Saints' Day": "Toussaint",
"Immaculate Conception": "Immaculée Conception",
"Christmas Day": "Noël",
"St. Stephen's Day": "Saint-Étienne"
}
16 changes: 16 additions & 0 deletions lang/switzerland/it/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"New Year's Day": "Capodanno",
"Berchtold's Day": "Giorno di Berchtold",
"St. Joseph's Day": "Giorno di San Giuseppe",
"Good Friday": "Venerdì santo",
"Easter Monday": "Lunedì di Pasqua",
"Ascension Day": "Ascensione",
"Whit Monday": "Glindesdi da Pentecosta",
"Corpus Christi": "Corpus Domini",
"Swiss National Day": "Festa nazionale",
"Assumption Day": "Assunta",
"All Saints' Day": "Ognissanti",
"Immaculate Conception": "Immacolata Concezione",
"Christmas Day": "Natale",
"St. Stephen's Day": "San Steffan"
}
16 changes: 16 additions & 0 deletions lang/switzerland/rm/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"New Year's Day": "Bun di bun onn",
"Berchtold's Day": "Bun di San Berchtold",
"St. Joseph's Day": "Bun di San Giusep",
"Good Friday": "Venerdi San",
"Easter Monday": "Lun di Pasca",
"Ascension Day": "Ascensiun",
"Whit Monday": "Lun di Pentecoste",
"Corpus Christi": "Corpus Christi",
"Swiss National Day": "Festa naziunala",
"Assumption Day": "Assunziun",
"All Saints' Day": "Ognissanti",
"Immaculate Conception": "Immaculada Conceziun",
"Christmas Day": "Nadal",
"St. Stephen's Day": "San Stefaun"
}
77 changes: 25 additions & 52 deletions src/Countries/Switzerland.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,13 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Concerns\Translatable;

class Switzerland extends Country
{
const HOLIDAYS = [
'New Year\'s Day' => ['de' => 'Neujahrstag', 'fr' => 'Nouvel an', 'it' => 'Capodanno', 'rm' => 'Bun di bun onn'],
'Berchtold Day' => ['de' => 'Berchtoldstag', 'fr' => '2 janvier', 'it' => 'Giorno di Berchtold', 'rm' => 'Di da Berchtold'],
'St. Joseph\'s Day' => ['de' => 'Josefstag', 'fr' => 'Saint-Joseph', 'it' => 'Giorno di San Giuseppe', 'rm' => 'Di da San Giusep'],
'Good Friday' => ['de' => 'Karfreitag', 'fr' => 'Vendredi saint', 'it' => 'Venerdì santo', 'rm' => 'Venderdi santo'],
'Easter Monday' => ['de' => 'Ostermontag', 'fr' => 'Lundi de Pâques', 'it' => 'Lunedì di Pasqua', 'rm' => 'Glindesdi da Pasca'],
'Ascension Day' => ['de' => 'Auffahrt', 'fr' => 'Ascension', 'it' => 'Ascensione', 'rm' => 'Ascensiun'],
'Whit Monday' => ['de' => 'Pfingstmontag', 'fr' => 'Lundi de Pentecôte', 'it' => 'Lunedì di Pentecoste', 'rm' => 'Glindesdi da Pentecosta'],
'Corpus Christi' => ['de' => 'Fronleichnam', 'fr' => 'Fête-Dieu', 'it' => 'Corpus Domini', 'rm' => 'Corpus Christi'],
'Swiss National Day' => ['de' => 'Bundesfeier', 'fr' => 'Fête nationale', 'it' => 'Festa nazionale', 'rm' => 'Fiasta naziunala'],
'Assumption Day' => ['de' => 'Maria Himmelfahrt', 'fr' => 'Assomption', 'it' => 'Assunzione', 'rm' => 'Assunta'],
'All Saints\' Day' => ['de' => 'Allerheiligen', 'fr' => 'Toussaint', 'it' => 'Ognissanti', 'rm' => 'Ognissants'],
'Immaculate Conception' => ['de' => 'Maria Empfängnis', 'fr' => 'Immaculée Conception', 'it' => 'Immacolata Concezione', 'rm' => 'Concepziun da Maria'],
'Christmas Day' => ['de' => 'Weihnachtstag', 'fr' => 'Noël', 'it' => 'Natale', 'rm' => 'Nadal'],
'St. Stephen\'s Day' => ['de' => 'Stephanstag', 'fr' => 'Saint-Étienne', 'it' => 'Santo Stefano', 'rm' => 'San Steffan'],
];

protected function __construct(
protected ?string $region = null,
protected string $locale = 'de',
protected ?string $region = null
) {
}

Expand All @@ -38,25 +22,25 @@ protected function allHolidays(int $year): array
{

return array_merge([
$this->trans('Swiss National Day')=> '08-01',
'Swiss National Day' => '08-01',
],
$this->region ? $this->getRegionHolidays($year) : $this->getSwissHolidays($year),
$this->region ? $this->getRegionHolidays($year) : $this->getDefaultSwissHolidays($year),
);
}

/**
* This defaults to SBB/CFF/FFS holidays or postal holidays
* https://github.com/spatie/holidays/pull/49/files#r1462344840
* @return array<string, CarbonImmutable>
* @return array<string, string|CarbonImmutable>
*/
private function getSwissHolidays(int $year): array
private function getDefaultSwissHolidays(int $year): array
{

return array_merge([
$this->trans('New Year\'s Day') => '01-01',
$this->trans('Berchtold Day') => '01-02',
$this->trans('Christmas Day') => '12-25',
$this->trans('St. Stephen\'s Day') => '12-26',
'New Year\'s Day' => '01-01',
'Berchtold\'s Day' => '01-02',
'Christmas Day' => '12-25',
'St. Stephen\'s Day' => '12-26',
], $this->getEasterHolidays($year));
}

Expand All @@ -67,23 +51,23 @@ private function getEasterHolidays(int $year, bool $with_good_friday = true, boo
$easter = $this->easter($year);

$easter_holidays = [
$this->trans('Easter Monday') => $easter->addDay(),
$this->trans('Ascension Day') => $easter->addDays(39),
$this->trans('Whit Monday') => $easter->addDays(50),
'Easter Monday' => $easter->addDay(),
'Ascension Day' => $easter->addDays(39),
'Whit Monday' => $easter->addDays(50),
];

if ($with_good_friday) {
$easter_holidays[$this->trans('Good Friday')] = $easter->subDays(2);
$easter_holidays['Good Friday'] = $easter->subDays(2);
}

if ($with_corpus_christi) {
$easter_holidays[$this->trans('Corpus Christi')] = $easter->addDays(60);
$easter_holidays['Corpus Christi'] = $easter->addDays(60);
}

return $easter_holidays;
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, string|CarbonImmutable> */
private function getRegionHolidays(int $year): array
{

Expand All @@ -99,6 +83,7 @@ private function getRegionHolidays(int $year): array
return $this->getCantonHolidays($canton, $year);
}

/** @return array<string, string|CarbonImmutable> */
private function getCantonHolidays(string $canton, int $year): array
{
return match ($canton) {
Expand All @@ -107,32 +92,20 @@ private function getCantonHolidays(string $canton, int $year): array
};
}

private function trans(string $key): string
{

// return translation if available
if (isset(self::HOLIDAYS[$key][$this->locale])) {
return self::HOLIDAYS[$key][$this->locale];
}

// return key if no translation is available
return $key;
}

/** @return array<string, string> */
private function getVSHolidays(int $year): array
{
$eastern_holidays = $this->getEasterHolidays($year, with_good_friday: false, with_corpus_christi: true);

return array_merge([
$this->trans('New Year\'s Day') => '01-01',
$this->trans('Berchtold Day') => '01-02',
$this->trans('St. Joseph\'s Day') => '03-19', // St. Joseph
$this->trans('Assumption Day') => '08-15', // Assumption
$this->trans('All Saints\' Day') => '11-01', // All Saints
$this->trans('Immaculate Conception') => '12-08', // Immaculate Conception
$this->trans('Christmas Day') => '12-25',
$this->trans('St. Stephen\'s Day') => '12-26',
'New Year\'s Day' => '01-01',
'Berchtold\'s Day' => '01-02',
'St. Joseph\'s Day' => '03-19',
'Assumption Day' => '08-15',
'All Saints\' Day' => '11-01',
'Immaculate Conception' => '12-08',
'Christmas Day' => '12-25',
'St. Stephen\'s Day' => '12-26',
], $eastern_holidays);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Countries/SwitzerlandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(Switzerland::make('ch-vs', $language))->get();
$country = Switzerland::make('ch-vs');

$holidays = Holidays::for($country, locale: $language)->get();

expect($holidays)
->toBeArray()
Expand Down

0 comments on commit f866e82

Please sign in to comment.