blob: 75e3a2fa76a5a7b180e53cd65f0d890be6752602 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Translation;
13
14use Symfony\Component\Config\Resource\ResourceInterface;
15
16/**
17 * MessageCatalogueInterface.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 */
21interface MessageCatalogueInterface
22{
23 public const INTL_DOMAIN_SUFFIX = '+intl-icu';
24
25 /**
26 * Gets the catalogue locale.
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020027 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010028 public function getLocale(): string;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020029
30 /**
31 * Gets the domains.
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020032 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010033 public function getDomains(): array;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020034
35 /**
36 * Gets the messages within a given domain.
37 *
38 * If $domain is null, it returns all messages.
39 *
40 * @param string $domain The domain name
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020041 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010042 public function all(string $domain = null): array;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020043
44 /**
45 * Sets a message translation.
46 *
47 * @param string $id The message id
48 * @param string $translation The messages translation
49 * @param string $domain The domain name
50 */
51 public function set(string $id, string $translation, string $domain = 'messages');
52
53 /**
54 * Checks if a message has a translation.
55 *
56 * @param string $id The message id
57 * @param string $domain The domain name
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020058 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010059 public function has(string $id, string $domain = 'messages'): bool;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020060
61 /**
62 * Checks if a message has a translation (it does not take into account the fallback mechanism).
63 *
64 * @param string $id The message id
65 * @param string $domain The domain name
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020066 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010067 public function defines(string $id, string $domain = 'messages'): bool;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020068
69 /**
70 * Gets a message translation.
71 *
72 * @param string $id The message id
73 * @param string $domain The domain name
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020074 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010075 public function get(string $id, string $domain = 'messages'): string;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020076
77 /**
78 * Sets translations for a given domain.
79 *
80 * @param array $messages An array of translations
81 * @param string $domain The domain name
82 */
83 public function replace(array $messages, string $domain = 'messages');
84
85 /**
86 * Adds translations for a given domain.
87 *
88 * @param array $messages An array of translations
89 * @param string $domain The domain name
90 */
91 public function add(array $messages, string $domain = 'messages');
92
93 /**
94 * Merges translations from the given Catalogue into the current one.
95 *
96 * The two catalogues must have the same locale.
97 */
98 public function addCatalogue(self $catalogue);
99
100 /**
101 * Merges translations from the given Catalogue into the current one
102 * only when the translation does not exist.
103 *
104 * This is used to provide default translations when they do not exist for the current locale.
105 */
106 public function addFallbackCatalogue(self $catalogue);
107
108 /**
109 * Gets the fallback catalogue.
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200110 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100111 public function getFallbackCatalogue(): ?self;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200112
113 /**
114 * Returns an array of resources loaded to build this collection.
115 *
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100116 * @return ResourceInterface[]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200117 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100118 public function getResources(): array;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200119
120 /**
121 * Adds a resource for this collection.
122 */
123 public function addResource(ResourceInterface $resource);
124}