blob: 5d83bd8a9d614c46b3e2efa6b3b5b9b164d10a83 [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.
27 *
28 * @return string The locale
29 */
30 public function getLocale();
31
32 /**
33 * Gets the domains.
34 *
35 * @return array An array of domains
36 */
37 public function getDomains();
38
39 /**
40 * Gets the messages within a given domain.
41 *
42 * If $domain is null, it returns all messages.
43 *
44 * @param string $domain The domain name
45 *
46 * @return array An array of messages
47 */
48 public function all(string $domain = null);
49
50 /**
51 * Sets a message translation.
52 *
53 * @param string $id The message id
54 * @param string $translation The messages translation
55 * @param string $domain The domain name
56 */
57 public function set(string $id, string $translation, string $domain = 'messages');
58
59 /**
60 * Checks if a message has a translation.
61 *
62 * @param string $id The message id
63 * @param string $domain The domain name
64 *
65 * @return bool true if the message has a translation, false otherwise
66 */
67 public function has(string $id, string $domain = 'messages');
68
69 /**
70 * Checks if a message has a translation (it does not take into account the fallback mechanism).
71 *
72 * @param string $id The message id
73 * @param string $domain The domain name
74 *
75 * @return bool true if the message has a translation, false otherwise
76 */
77 public function defines(string $id, string $domain = 'messages');
78
79 /**
80 * Gets a message translation.
81 *
82 * @param string $id The message id
83 * @param string $domain The domain name
84 *
85 * @return string The message translation
86 */
87 public function get(string $id, string $domain = 'messages');
88
89 /**
90 * Sets translations for a given domain.
91 *
92 * @param array $messages An array of translations
93 * @param string $domain The domain name
94 */
95 public function replace(array $messages, string $domain = 'messages');
96
97 /**
98 * Adds translations for a given domain.
99 *
100 * @param array $messages An array of translations
101 * @param string $domain The domain name
102 */
103 public function add(array $messages, string $domain = 'messages');
104
105 /**
106 * Merges translations from the given Catalogue into the current one.
107 *
108 * The two catalogues must have the same locale.
109 */
110 public function addCatalogue(self $catalogue);
111
112 /**
113 * Merges translations from the given Catalogue into the current one
114 * only when the translation does not exist.
115 *
116 * This is used to provide default translations when they do not exist for the current locale.
117 */
118 public function addFallbackCatalogue(self $catalogue);
119
120 /**
121 * Gets the fallback catalogue.
122 *
123 * @return self|null A MessageCatalogueInterface instance or null when no fallback has been set
124 */
125 public function getFallbackCatalogue();
126
127 /**
128 * Returns an array of resources loaded to build this collection.
129 *
130 * @return ResourceInterface[] An array of resources
131 */
132 public function getResources();
133
134 /**
135 * Adds a resource for this collection.
136 */
137 public function addResource(ResourceInterface $resource);
138}