home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Numbers / Words / lang.id.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  7.8 KB  |  278 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4.0                                                      |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2001 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 3.0 of the PHP license,       |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/3_0.txt.                                  |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Ernas M. Jamil <ernasm@samba.co.id>, Arif Rifai Dwiyanto    |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.id.php,v 1.1 2004/09/02 11:07:59 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Indonesian language.
  23. //
  24.  
  25. require_once("PEAR.php");
  26. require_once("Numbers/Words.php");
  27.  
  28. /**
  29. * Class for translating numbers into Indonesian.
  30. *
  31. * @author Ernas M. Jamil, Arif Rifai Dwiyanto
  32. */
  33. class Numbers_Words_id extends Numbers_Words
  34. {
  35.  
  36.     // {{{ properties
  37.     
  38.     /**
  39.     * Locale name
  40.     * @var string
  41.     */
  42.     var $locale      = 'id';
  43.  
  44.     /**
  45.     * Language name in English
  46.     * @var string
  47.     */
  48.     var $lang        = 'Indonesia Language';
  49.  
  50.     /**
  51.     * Native language name
  52.     * @var string
  53.     */
  54.     var $lang_native = 'Bahasa Indonesia';
  55.     
  56.     /**
  57.     * The word for the minus sign
  58.     * @var string
  59.     */
  60.     var $_minus = 'minus'; // minus sign
  61.  
  62.     /**
  63.     * The sufixes for exponents (singular and plural)
  64.     * Names partly based on:
  65.     * http://www.users.dircon.co.uk/~shaunf/shaun/numbers/millions.htm
  66.     * @var array
  67.     */
  68.     var $_exponent = array(
  69.         0 => array(''),
  70.         3 => array('ribu'),
  71.         6 => array('juta'),
  72.         9 => array('milyar'),
  73.        12 => array('trilyun'),
  74.        24 => array('quadrillion'),
  75.        30 => array('quintillion'),
  76.        36 => array('sextillion'),
  77.        42 => array('septillion'),
  78.        48 => array('octillion'),
  79.        54 => array('nonillion'),
  80.        60 => array('decillion'),
  81.        66 => array('undecillion'),
  82.        72 => array('duodecillion'),
  83.        78 => array('tredecillion'),
  84.        84 => array('quattuordecillion'),
  85.        90 => array('quindecillion'),
  86.        96 => array('sexdecillion'),
  87.       102 => array('septendecillion'),
  88.       108 => array('octodecillion'),
  89.       114 => array('novemdecillion'),
  90.       120 => array('vigintillion'),
  91.       192 => array('duotrigintillion'),
  92.       600 => array('centillion')
  93.         );
  94.  
  95.     /**
  96.     * The array containing the digits (indexed by the digits themselves).
  97.     * @var array
  98.     */
  99.     var $_digits = array(
  100.         0 => 'nol', 'satu', 'dua', 'tiga', 'empat',
  101.         'lima', 'enam', 'tujuh', 'delapan', 'sembilan'
  102.     );
  103.  
  104.     /**
  105.     * The word separator
  106.     * @var string
  107.     */
  108.     var $_sep = ' ';
  109.  
  110.     // }}}
  111.     // {{{ toWords()
  112.  
  113.     /**
  114.      * Converts a number to its word representation
  115.      * in Indonesian language
  116.      *
  117.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  118.      *                        that need to be converted to words
  119.      * @param  integer $power The power of ten for the rest of the number to the right.
  120.      *                        Optional, defaults to 0.
  121.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  122.      *                        Used internally. Optional, defaults to ''.
  123.      *
  124.      * @return string  The corresponding word representation
  125.      *
  126.      * @access public
  127.      * @author Ernas M. Jamil
  128.      * @since  PHP 4.2.3
  129.      */
  130.     function toWords($num, $power = 0, $powsuffix = '') {
  131.       $ret = '';        
  132.         
  133.       // add a minus sign
  134.       if (substr($num, 0, 1) == '-') {
  135.         $ret = $this->_sep . $this->_minus;
  136.         $num = substr($num, 1);
  137.       }
  138.         
  139.       // strip excessive zero signs and spaces
  140.       $num = trim($num);
  141.       $num = preg_replace('/^0+/','',$num);
  142.         
  143.       if (strlen($num) > 4) {
  144.           $maxp = strlen($num)-1;
  145.           $curp = $maxp;
  146.           for ($p = $maxp; $p > 0; --$p) { // power
  147.             
  148.             // check for highest power
  149.             if (isset($this->_exponent[$p])) {
  150.               // send substr from $curp to $p
  151.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  152.               $snum = preg_replace('/^0+/','',$snum);
  153.               if ($snum !== '') {
  154.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  155.                   if ($powsuffix != '')
  156.                     $cursuffix .= $this->_sep . $powsuffix;
  157.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  158.               }
  159.               $curp = $p - 1;
  160.               continue;
  161.             }
  162.           }
  163.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  164.           if ($num == 0) {
  165.               return $ret;
  166.           }
  167.       } elseif ($num == 0 || $num == '') {
  168.         return $this->_sep . $this->_digits[0];
  169.       }
  170.     
  171.       $h = $t = $d = $th = 0;
  172.       
  173.       switch(strlen($num)) {
  174.         case 4:
  175.           $th = (int)substr($num,-4,1);
  176.  
  177.         case 3:
  178.           $h = (int)substr($num,-3,1);
  179.  
  180.         case 2:
  181.           $t = (int)substr($num,-2,1);
  182.  
  183.         case 1:
  184.           $d = (int)substr($num,-1,1);
  185.           break;
  186.  
  187.         case 0:
  188.           return;
  189.           break;
  190.       }
  191.  
  192.       if ($th) {
  193.         if ($th==1)
  194.             $ret .= $this->_sep . 'seribu';
  195.         else
  196.             $ret .= $this->_sep . $this->_digits[$th] . $this->_sep . 'ribu';
  197.       }
  198.  
  199.       if ($h) {
  200.         if ($h==1)
  201.             $ret .= $this->_sep . 'seratus';
  202.         else
  203.             $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'ratus';
  204.         
  205.         // in English only - add ' and' for [1-9]01..[1-9]99
  206.         // (also for 1001..1099, 10001..10099 but it is harder)
  207.         // for now it is switched off, maybe some language purists
  208.         // can force me to enable it, or to remove it completely
  209.         // if (($t + $d) > 0)
  210.         //   $ret .= $this->_sep . 'and';
  211.       }
  212.  
  213.       // ten, twenty etc.
  214.       switch ($t) {
  215.       case 9:
  216.       case 8:
  217.       case 7:
  218.       case 6:
  219.       case 5:
  220.       case 4:
  221.       case 3:
  222.       case 2:
  223.           $ret .= $this->_sep . $this->_digits[$t] . ' puluh';
  224.           break;
  225.     
  226.       case 1:
  227.           switch ($d) {
  228.           case 0:
  229.               $ret .= $this->_sep . 'sepuluh';
  230.               break;
  231.     
  232.           case 1:
  233.               $ret .= $this->_sep . 'sebelas';
  234.               break;
  235.     
  236.           case 2:
  237.           case 3:
  238.           case 4:
  239.           case 5:
  240.           case 6:
  241.           case 7:
  242.           case 8:
  243.           case 9:
  244.               $ret .= $this->_sep . $this->_digits[$d] . ' belas';
  245.               break;
  246.           }
  247.           break; 
  248.       }
  249.  
  250.       if ($t != 1 && $d > 0) { // add digits only in <0>,<1,9> and <21,inf>
  251.         // add minus sign between [2-9] and digit
  252.         if ($t > 1) {
  253.           $ret .= ' ' . $this->_digits[$d];
  254.         } else {
  255.           $ret .= $this->_sep . $this->_digits[$d];
  256.         }
  257.       }
  258.   
  259.       if ($power > 0) {
  260.         if (isset($this->_exponent[$power]))
  261.           $lev = $this->_exponent[$power];
  262.     
  263.         if (!isset($lev) || !is_array($lev))
  264.           return null;
  265.      
  266.         $ret .= $this->_sep . $lev[0];
  267.       }
  268.     
  269.       if ($powsuffix != '')
  270.         $ret .= $this->_sep . $powsuffix;
  271.     
  272.       return $ret;
  273.     }
  274.     // }}}
  275. }
  276.  
  277. ?>
  278.