/bp-forums/bbpress/bb-includes/backpress/pomo/sample/app.php

  1. <?php 
  2.  
  3. require_once dirname( dirname(__FILE__) ) . '/translations.php'; 
  4. require_once dirname( dirname(__FILE__) ) . '/mo.php'; 
  5.  
  6.  
  7. function __($text, $domain = 'default') { 
  8. $translations = &get_translations($domain); 
  9. return $translations->translate($text); 
  10.  
  11. function _e($text, $domain = 'default') { 
  12. $translations = &get_translations($domain); 
  13. echo $translations->translate($text); 
  14.  
  15. function __n($singular, $plural, $count, $domain = 'default') { 
  16. $translations = &get_translations($domain); 
  17. return $translations->translate_plural($singular, $plural, $count); 
  18.  
  19. function &load_translations($mo_filename) { 
  20. if (is_readable($mo_filename)) { 
  21. $translations = new MO(); 
  22. $translations->import_from_file($mo_filename); 
  23. } else { 
  24. $translations = new Translations(); 
  25. return $translations; 
  26.  
  27. // get the locale from somewhere: subomain, config, GET var, etc. 
  28. // it can be safely empty 
  29. $locale = 'bg'; 
  30. $translations = array(); 
  31. $empty_translations = & new Translations(); 
  32.  
  33. function load_textdomain($domain, $mofile) { 
  34. global $translations; 
  35. $translations[$domain] = &load_translations($mofile); 
  36.  
  37. function &get_translations($domain) { 
  38. global $translations, $empty_translations; 
  39. return isset($translations[$domain])? $translations[$domain] : $empty_translations; 
  40.  
  41. // load the translations 
  42. load_textdomain('default', "languages/$locale.mo"); 
  43. load_textdomain('side', "languages/$locale-side.mo"); 
  44.  
  45. //here comes the real app 
  46. $user = 'apok'; 
  47. $messages = rand(0, 2); 
  48.  
  49. printf(__('Welcome %s!')."\n", $user); 
  50.  
  51. printf(__n('You have one new message.', 'You have %s new messages.', $messages)."\n", $messages); 
  52.  
  53. echo __("A string with low priority!", 'side')."\n"; 
  54.  
  55. _e("Bye\n"); 
.