[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/bbpress/bb-includes/backpress/pomo/sample/ -> app.php (source)

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


Generated: Sat Sep 21 01:01:46 2019 Cross-referenced by PHPXref 0.7.1