generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from spatie/feature/localization
Add support for multi languages
- Loading branch information
Showing
7 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Nieuwjaar": "Jour de l'An", | ||
"Dag van de Arbeid": "Fête du Travail", | ||
"Nationale Feestdag": "Fête nationale", | ||
"OLV Hemelvaart": "Assomption", | ||
"Allerheiligen": "Toussaint", | ||
"Wapenstilstand": "Armistice", | ||
"Kerstmis": "Noël", | ||
"Paasmaandag": "Lundi de Pâques", | ||
"OLH Hemelvaart": "Ascension", | ||
"Pinkstermaandag": "Lundi de Pentecôte" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Concerns; | ||
|
||
use Spatie\Holidays\Exceptions\InvalidLocale; | ||
|
||
trait Translatable | ||
{ | ||
protected function translate(string $country, string $name, ?string $locale = null): string | ||
{ | ||
if ($locale === null) { | ||
return $name; | ||
} | ||
|
||
$countryName = strtolower($country); | ||
|
||
$content = file_get_contents(__DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"); | ||
|
||
if ($content === false) { | ||
throw InvalidLocale::notFound($country, $locale); | ||
} | ||
|
||
/** @var array<string, string> $data */ | ||
$data = json_decode($content, true); | ||
|
||
if (! isset($data[$name])) { | ||
return $name; | ||
} | ||
|
||
return $data[$name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class InvalidLocale extends RuntimeException | ||
{ | ||
public static function notFound(string $country, string $locale): self | ||
{ | ||
return new self("Locale `{$locale}` is not supported for country `{$country}`."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters