Numbers_Words
[ class tree: Numbers_Words ] [ index: Numbers_Words ] [ all elements ]

Source for file lang.id.php

Documentation is available at lang.id.php

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

Documentation generated on Mon, 11 Mar 2019 13:56:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.