-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathIntlConfig.php
More file actions
51 lines (40 loc) · 1.46 KB
/
IntlConfig.php
File metadata and controls
51 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Tempest\Intl;
use Tempest\Intl\MessageFormat\FormattingFunction;
use Tempest\Intl\MessageFormat\MarkupFormatter;
use Tempest\Intl\MessageFormat\SelectorFunction;
use Tempest\Intl\MessageFormat\StandaloneMarkupFormatter;
final class IntlConfig
{
/** @var FormattingFunction[] */
public array $functions = [];
/** @var array<MarkupFormatter|StandaloneMarkupFormatter> */
public array $markupFormatters = [];
/** @var array<string,string[]> */
public array $translationMessagePaths = [];
public function __construct(
/**
* Defines the locale used throughout the application.
*/
public Locale $currentLocale,
/**
* Defines the fallback locale used when a translation message does not exist in the current locale.
*/
public Locale $fallbackLocale,
) {}
public function addFunction(FormattingFunction|SelectorFunction $fn): void
{
$this->functions[] = $fn;
}
public function addMarkupFormatter(MarkupFormatter|StandaloneMarkupFormatter $formatter): void
{
$this->markupFormatters[] = $formatter;
}
public function addTranslationMessageFile(Locale $locale, string $path): void
{
$this->translationMessagePaths[$locale->value] ??= [];
if (! in_array($path, $this->translationMessagePaths[$locale->value], strict: true)) {
$this->translationMessagePaths[$locale->value][] = $path;
}
}
}