I18n.php 499 B

123456789101112131415161718192021
  1. <?php
  2. class I18n
  3. {
  4. // Variable to be interpolated
  5. public $name = 'Bob';
  6. // Add a {{#__}} lambda for i18n
  7. public $__ = array(__CLASS__, '__trans');
  8. // A *very* small i18n dictionary :)
  9. private static $dictionary = array(
  10. 'Hello.' => 'Hola.',
  11. 'My name is {{ name }}.' => 'Me llamo {{ name }}.',
  12. );
  13. public static function __trans($text)
  14. {
  15. return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
  16. }
  17. }