I18n.php 710 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2017 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class I18n
  11. {
  12. // Variable to be interpolated
  13. public $name = 'Bob';
  14. // Add a {{#__}} lambda for i18n
  15. public $__ = array(__CLASS__, '__trans');
  16. // A *very* small i18n dictionary :)
  17. private static $dictionary = array(
  18. 'Hello.' => 'Hola.',
  19. 'My name is {{ name }}.' => 'Me llamo {{ name }}.',
  20. );
  21. public static function __trans($text)
  22. {
  23. return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
  24. }
  25. }