Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 1 | <?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 | |
| 12 | namespace Symfony\Component\Translation; |
| 13 | |
| 14 | use Symfony\Component\Config\Resource\ResourceInterface; |
| 15 | |
| 16 | /** |
| 17 | * MessageCatalogueInterface. |
| 18 | * |
| 19 | * @author Fabien Potencier <fabien@symfony.com> |
| 20 | */ |
| 21 | interface MessageCatalogueInterface |
| 22 | { |
| 23 | public const INTL_DOMAIN_SUFFIX = '+intl-icu'; |
| 24 | |
| 25 | /** |
| 26 | * Gets the catalogue locale. |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 27 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 28 | public function getLocale(): string; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Gets the domains. |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 32 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 33 | public function getDomains(): array; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 34 | |
| 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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 41 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 42 | public function all(string $domain = null): array; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 43 | |
| 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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 58 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 59 | public function has(string $id, string $domain = 'messages'): bool; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 60 | |
| 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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 66 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 67 | public function defines(string $id, string $domain = 'messages'): bool; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Gets a message translation. |
| 71 | * |
| 72 | * @param string $id The message id |
| 73 | * @param string $domain The domain name |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 74 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 75 | public function get(string $id, string $domain = 'messages'): string; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 76 | |
| 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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 110 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 111 | public function getFallbackCatalogue(): ?self; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Returns an array of resources loaded to build this collection. |
| 115 | * |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 116 | * @return ResourceInterface[] |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 117 | */ |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 118 | public function getResources(): array; |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Adds a resource for this collection. |
| 122 | */ |
| 123 | public function addResource(ResourceInterface $resource); |
| 124 | } |