TranslatorInterface.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Contracts\Translation;
  11. /**
  12. * @author Fabien Potencier <fabien@symfony.com>
  13. */
  14. interface TranslatorInterface
  15. {
  16. /**
  17. * Translates the given message.
  18. *
  19. * When a number is provided as a parameter named "%count%", the message is parsed for plural
  20. * forms and a translation is chosen according to this number using the following rules:
  21. *
  22. * Given a message with different plural translations separated by a
  23. * pipe (|), this method returns the correct portion of the message based
  24. * on the given number, locale and the pluralization rules in the message
  25. * itself.
  26. *
  27. * The message supports two different types of pluralization rules:
  28. *
  29. * interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples
  30. * indexed: There is one apple|There are %count% apples
  31. *
  32. * The indexed solution can also contain labels (e.g. one: There is one apple).
  33. * This is purely for making the translations more clear - it does not
  34. * affect the functionality.
  35. *
  36. * The two methods can also be mixed:
  37. * {0} There are no apples|one: There is one apple|more: There are %count% apples
  38. *
  39. * An interval can represent a finite set of numbers:
  40. * {1,2,3,4}
  41. *
  42. * An interval can represent numbers between two numbers:
  43. * [1, +Inf]
  44. * ]-1,2[
  45. *
  46. * The left delimiter can be [ (inclusive) or ] (exclusive).
  47. * The right delimiter can be [ (exclusive) or ] (inclusive).
  48. * Beside numbers, you can use -Inf and +Inf for the infinite.
  49. *
  50. * @see https://en.wikipedia.org/wiki/ISO_31-11
  51. *
  52. * @param string $id The message id (may also be an object that can be cast to string)
  53. * @param array $parameters An array of parameters for the message
  54. * @param string|null $domain The domain for the message or null to use the default
  55. * @param string|null $locale The locale or null to use the default
  56. *
  57. * @return string The translated string
  58. *
  59. * @throws \InvalidArgumentException If the locale contains invalid characters
  60. */
  61. public function trans($id, array $parameters = [], $domain = null, $locale = null);
  62. }