MessageCatalogueInterface.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation;
  11. use Symfony\Component\Config\Resource\ResourceInterface;
  12. /**
  13. * MessageCatalogueInterface.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. interface MessageCatalogueInterface
  18. {
  19. /**
  20. * Gets the catalogue locale.
  21. *
  22. * @return string The locale
  23. */
  24. public function getLocale();
  25. /**
  26. * Gets the domains.
  27. *
  28. * @return array An array of domains
  29. */
  30. public function getDomains();
  31. /**
  32. * Gets the messages within a given domain.
  33. *
  34. * If $domain is null, it returns all messages.
  35. *
  36. * @param string $domain The domain name
  37. *
  38. * @return array An array of messages
  39. */
  40. public function all($domain = null);
  41. /**
  42. * Sets a message translation.
  43. *
  44. * @param string $id The message id
  45. * @param string $translation The messages translation
  46. * @param string $domain The domain name
  47. */
  48. public function set($id, $translation, $domain = 'messages');
  49. /**
  50. * Checks if a message has a translation.
  51. *
  52. * @param string $id The message id
  53. * @param string $domain The domain name
  54. *
  55. * @return bool true if the message has a translation, false otherwise
  56. */
  57. public function has($id, $domain = 'messages');
  58. /**
  59. * Checks if a message has a translation (it does not take into account the fallback mechanism).
  60. *
  61. * @param string $id The message id
  62. * @param string $domain The domain name
  63. *
  64. * @return bool true if the message has a translation, false otherwise
  65. */
  66. public function defines($id, $domain = 'messages');
  67. /**
  68. * Gets a message translation.
  69. *
  70. * @param string $id The message id
  71. * @param string $domain The domain name
  72. *
  73. * @return string The message translation
  74. */
  75. public function get($id, $domain = 'messages');
  76. /**
  77. * Sets translations for a given domain.
  78. *
  79. * @param array $messages An array of translations
  80. * @param string $domain The domain name
  81. */
  82. public function replace($messages, $domain = 'messages');
  83. /**
  84. * Adds translations for a given domain.
  85. *
  86. * @param array $messages An array of translations
  87. * @param string $domain The domain name
  88. */
  89. public function add($messages, $domain = 'messages');
  90. /**
  91. * Merges translations from the given Catalogue into the current one.
  92. *
  93. * The two catalogues must have the same locale.
  94. */
  95. public function addCatalogue(self $catalogue);
  96. /**
  97. * Merges translations from the given Catalogue into the current one
  98. * only when the translation does not exist.
  99. *
  100. * This is used to provide default translations when they do not exist for the current locale.
  101. */
  102. public function addFallbackCatalogue(self $catalogue);
  103. /**
  104. * Gets the fallback catalogue.
  105. *
  106. * @return self|null A MessageCatalogueInterface instance or null when no fallback has been set
  107. */
  108. public function getFallbackCatalogue();
  109. /**
  110. * Returns an array of resources loaded to build this collection.
  111. *
  112. * @return ResourceInterface[] An array of resources
  113. */
  114. public function getResources();
  115. /**
  116. * Adds a resource for this collection.
  117. */
  118. public function addResource(ResourceInterface $resource);
  119. }