MessageTemplate.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Elgg\I18n;
  3. /**
  4. * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
  5. *
  6. * A single localizable message template.
  7. *
  8. * We introduced this class because we want to have the flexibility of
  9. * easily switching our message template language from sprintf to ICU...
  10. *
  11. * Example messages:
  12. * - "{subject} spent {num_nights,number,integer} nights camping in {location}." (ICU)
  13. * - "%s spent %d nights camping in %s" (sprintf)
  14. *
  15. * @since 1.11
  16. *
  17. * @access private
  18. */
  19. abstract class MessageTemplate {
  20. /** @var string */
  21. protected $template;
  22. /**
  23. * Constructor
  24. *
  25. * @param string $template The message template
  26. */
  27. public function __construct($template) {
  28. $this->template = $template;
  29. }
  30. /**
  31. * Applies the inputs to the message template and returns the result.
  32. *
  33. * @param array $args The inputs to this message
  34. *
  35. * @return string The rendered including all the interpolated inputs
  36. */
  37. public abstract function format(array $args);
  38. /**
  39. * Get the string template this message uses for translation.
  40. *
  41. * @return string
  42. */
  43. public function __toString() {
  44. return $this->template;
  45. }
  46. }