-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
19 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
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,54 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Latte (https://latte.nette.org) | ||
* Copyright (c) 2008 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Latte; | ||
|
||
|
||
final class Locale | ||
{ | ||
// currency: $fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, 'EUR'); | ||
|
||
private \Collator $collator; | ||
private \NumberFormatter $numberFormatter; | ||
private \NumberFormatter $moneyFormatter; | ||
private \IntlDateFormatter $dateFormatter; | ||
|
||
|
||
public function __construct( | ||
private string $locale, | ||
) { | ||
if (!extension_loaded('intl')) { | ||
throw new RuntimeException("Locate requires the 'intl' extension to be installed."); | ||
} | ||
} | ||
|
||
|
||
public function getCollator(): \Collator | ||
{ | ||
return $this->collator ??= new \Collator($this->locale); | ||
} | ||
|
||
|
||
public function getNumberFormatter(): \NumberFormatter | ||
{ | ||
return $this->numberFormatter ??= new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL); | ||
} | ||
|
||
|
||
public function getMoneyFormatter(): \NumberFormatter | ||
{ | ||
return $this->moneyFormatter ??= new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY); | ||
} | ||
|
||
|
||
public function getDateFormatter(): \IntlDateFormatter | ||
{ | ||
return $this->dateFormatter ??= new \IntlDateFormatter($this->locale, \IntlDateFormatter::FULL, \IntlDateFormatter::FULL); | ||
} | ||
} |