pastebin - collaborative debugging tool
kpaste.net RSS


TT Languages example
Posted by Admin on Sun 21st Mar 2010 23:47
raw | new post

  1. <?php
  2. // Plural forms: http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
  3. // $LANG["PLURAL_FORMS"] is in the plural= format
  4.  
  5. function T_ ($s) {
  6.         GLOBAL $LANG;
  7.  
  8.         if ($ret = $LANG[$s])
  9.                 return $ret;
  10.         if ($ret = $LANG["{$s}[0]"])
  11.                 return $ret;
  12.  
  13.         return $s;
  14. }
  15.  
  16. function P_ ($s, $num) {
  17.         GLOBAL $LANG;
  18.  
  19.         $num = (int) $num;
  20.  
  21.         $plural = str_replace("n", $num, $LANG["PLURAL_FORMS"]);
  22.         $i = eval("return intval($plural);");
  23.  
  24.         if ($ret = $LANG["{$s}[$i]"])
  25.                 return $ret;
  26.  
  27.         return $s;
  28. }
  29.  
  30. $LANG = array();
  31.  
  32. $LANG["PLURAL_FORMS"] = "n != 1";
  33.  
  34. $LANG["TORRENT[0]"] = "torrent";
  35. $LANG["TORRENT[1]"] = "torrents";
  36.  
  37.  
  38. echo "Singular: ".T_("TORRENT")."<br/>";
  39. echo "Plural: (n != 1): ".P_("TORRENT", 0)."<br/>";
  40. echo "Plural: (n == 1): ".P_("TORRENT", 1);
  41. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at