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.dk.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  12.4 KB  |  418 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4                                                        |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2003 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: Jesper Veggerby <pear.nosey@veggerby.dk>                    |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: lang.dk.php,v 1.2 2005/09/18 19:52:22 makler Exp $
  21. //
  22. // Numbers_Words class extension to spell numbers in Danish language.
  23. //
  24.  
  25. /**
  26.  * Class for translating numbers into Danish.
  27.  *
  28.  * @author Jesper Veggerby <pear.nosey@veggerby.dk>
  29.  * @package Numbers_Words
  30.  */
  31.  
  32. /**
  33.  * Include needed files
  34.  */
  35. require_once("Numbers/Words.php");
  36.  
  37. /**
  38.  * Class for translating numbers into Danish.
  39.  *
  40.  * @author Jesper Veggerby <pear.nosey@veggerby.dk>
  41.  * @package Numbers_Words
  42.  */
  43. class Numbers_Words_dk extends Numbers_Words
  44. {
  45.  
  46.     // {{{ properties
  47.  
  48.     /**
  49.      * Locale name
  50.      * @var string
  51.      * @access public
  52.      */
  53.     var $locale      = 'dk';
  54.  
  55.     /**
  56.      * Language name in English
  57.      * @var string
  58.      * @access public
  59.      */
  60.     var $lang        = 'Danish';
  61.  
  62.     /**
  63.      * Native language name
  64.      * @var string
  65.      * @access public
  66.      */
  67.     var $lang_native = 'Dansk';
  68.  
  69.     /**
  70.      * The word for the minus sign
  71.      * @var string
  72.      * @access private
  73.      */
  74.     var $_minus = 'minus'; // minus sign
  75.  
  76.     /**
  77.      * The sufixes for exponents (singular and plural).
  78.      * From: http://da.wikipedia.org/wiki/Navne_p%E5_store_tal
  79.      * @var array
  80.      * @access private
  81.      */
  82.     var $_exponent = array(
  83.         0 => array(''),
  84.         3 => array('tusind','tusinde'),
  85.         6 => array('million','millioner'),
  86.         9 => array('milliard','milliarder'),
  87.        12 => array('billion','billioner'),
  88.        15 => array('billiard','billiarder'),
  89.        18 => array('trillion','trillioner'),
  90.        21 => array('trilliard','trilliarder'),
  91.        24 => array('quadrillion','quadrillioner'),
  92.        30 => array('quintillion','quintillioner'),
  93.        36 => array('sextillion','sextillioner'),
  94.        42 => array('septillion','septillioner'),
  95.        48 => array('octillion','octillioner'),
  96.        54 => array('nonillion','nonillioner'),
  97.        60 => array('decillion','decillioner'),
  98.       120 => array('vigintillion','vigintillioner'),
  99.       600 => array('centillion','centillioner')
  100.         );
  101.  
  102.     /**
  103.      * The array containing the digits (indexed by the digits themselves).
  104.      * @var array
  105.      * @access private
  106.      */
  107.     var $_digits = array(
  108.         0 => 'nul', 'en', 'to', 'tre', 'fire',
  109.         'fem', 'seks', 'syv', 'otte', 'ni'
  110.     );
  111.  
  112.     /**
  113.      * The word separator
  114.      * @var string
  115.      * @access private
  116.      */
  117.     var $_sep  = ' ';
  118.  
  119.     /**
  120.      * The currency names (based on the below links,
  121.      * informations from central bank websites and on encyclopedias)
  122.      *
  123.      * @var array
  124.      * @link http://da.wikipedia.org/wiki/Valuta
  125.      * @access private
  126.      */
  127.     var $_currency_names = array(
  128.       'AUD' => array(array('australsk dollar', 'australske dollars'), array('cent')),
  129.       'CAD' => array(array('canadisk dollar', 'canadisk dollars'), array('cent')),
  130.       'CHF' => array(array('schweitzer franc'), array('rappen')),
  131.       'CYP' => array(array('cypriotisk pund', 'cypriotiske pund'), array('cent')),
  132.       'CZK' => array(array('tjekkisk koruna'), array('halerz')),
  133.       'DKK' => array(array('krone', 'kroner'), array('°re')),
  134.       'EUR' => array(array('euro'), array('euro-cent')),
  135.       'GBP' => array(array('pund'), array('pence')),
  136.       'HKD' => array(array('Hong Kong dollar', 'Hong Kong dollars'), array('cent')),
  137.       'JPY' => array(array('yen'), array('sen')),
  138.       'NOK' => array(array('norsk krone', 'norske kroner'), array('°re')),
  139.       'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
  140.       'SEK' => array(array('svensk krone', 'svenske kroner'), array('°re')),
  141.       'USD' => array(array('dollar', 'dollars'), array('cent'))
  142.     );
  143.  
  144.     /**
  145.      * The default currency name
  146.      * @var string
  147.      * @access public
  148.      */
  149.     var $def_currency = 'DKK'; // Danish krone
  150.  
  151.     // }}}
  152.     // {{{ toWords()
  153.  
  154.     /**
  155.      * Converts a number to its word representation
  156.      * in Danish language
  157.      *
  158.      * @param  integer $num   An integer between -infinity and infinity inclusive :)
  159.      *                        that need to be converted to words
  160.      * @param  integer $power The power of ten for the rest of the number to the right.
  161.      *                        Optional, defaults to 0.
  162.      * @param  integer $powsuffix The power name to be added to the end of the return string.
  163.      *                        Used internally. Optional, defaults to ''.
  164.      *
  165.      * @return string  The corresponding word representation
  166.      *
  167.      * @access public
  168.      * @author Jesper Veggerby <pear.nosey@veggerby.dk>
  169.      * @since  PHP 4.2.3
  170.      */
  171.     function toWords($num, $power = 0, $powsuffix = '') {
  172.       $ret = '';
  173.  
  174.       // add a minus sign
  175.       if (substr($num, 0, 1) == '-') {
  176.         $ret = $this->_sep . $this->_minus;
  177.         $num = substr($num, 1);
  178.       }
  179.  
  180.       // strip excessive zero signs and spaces
  181.       $num = trim($num);
  182.       $num = preg_replace('/^0+/','',$num);
  183.  
  184.       if (strlen($num) > 3) {
  185.           $maxp = strlen($num)-1;
  186.           $curp = $maxp;
  187.           for ($p = $maxp; $p > 0; --$p) { // power
  188.  
  189.             // check for highest power
  190.             if (isset($this->_exponent[$p])) {
  191.               // send substr from $curp to $p
  192.               $snum = substr($num, $maxp - $curp, $curp - $p + 1);
  193.               $snum = preg_replace('/^0+/','',$snum);
  194.               if ($snum !== '') {
  195.                   $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
  196.                   if ($powsuffix != '')
  197.                     $cursuffix .= $this->_sep . $powsuffix;
  198.                   $ret .= $this->toWords($snum, $p, $cursuffix);
  199.               }
  200.               $curp = $p - 1;
  201.               continue;
  202.             }
  203.           }
  204.           $num = substr($num, $maxp - $curp, $curp - $p + 1);
  205.           if ($num == 0) {
  206.               return $ret;
  207.           }
  208.       } elseif ($num == 0 || $num == '') {
  209.         return $this->_sep . $this->_digits[0];
  210.       }
  211.  
  212.       $h = $t = $d = 0;
  213.  
  214.       switch(strlen($num)) {
  215.         case 3:
  216.           $h = (int)substr($num,-3,1);
  217.  
  218.         case 2:
  219.           $t = (int)substr($num,-2,1);
  220.  
  221.         case 1:
  222.           $d = (int)substr($num,-1,1);
  223.           break;
  224.  
  225.         case 0:
  226.           return;
  227.           break;
  228.       }
  229.  
  230.       if ($h) {
  231.           if ($h == 1) {
  232.               $ret .= $this->_sep . 'et' . $this->_sep . 'hundrede';
  233.           } else {
  234.               $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'hundrede';
  235.           }
  236.  
  237.           //if (($t + $d) > 0)
  238.           //  $ret .= $this->_sep . 'og';
  239.       } elseif ((isset($maxp)) && ($maxp > 3)) {
  240.           // add 'og' in the case where there are preceding thousands but not hundreds or tens,
  241.           // so fx. 80001 becomes 'firs tusinde og en' instead of 'firs tusinde en'
  242.           $ret .= $this->_sep . 'og';
  243.       }
  244.  
  245.  
  246.       if ($t != 1 && $d > 0) {
  247.         $ret .= $this->_sep . (($d == 1 & $power == 3 && $t == 0 && $h == 0) ? "et" : $this->_digits[$d]) . ($t > 1 ? $this->_sep . "og" : "");
  248.       }
  249.  
  250.       // ten, twenty etc.
  251.       switch ($t) {
  252.       case 9:
  253.           $ret .= $this->_sep . 'halvfems';
  254.           break;
  255.  
  256.       case 8:
  257.           $ret .= $this->_sep . 'firs';
  258.           break;
  259.  
  260.       case 7:
  261.           $ret .= $this->_sep . 'halvfjerds';
  262.           break;
  263.  
  264.       case 6:
  265.           $ret .= $this->_sep . 'tres';
  266.           break;
  267.  
  268.       case 5:
  269.           $ret .= $this->_sep . 'halvtreds';
  270.           break;
  271.  
  272.       case 4:
  273.           $ret .= $this->_sep . 'fyrre';
  274.           break;
  275.  
  276.       case 3:
  277.           $ret .= $this->_sep . 'tredive';
  278.           break;
  279.  
  280.       case 2:
  281.           $ret .= $this->_sep . 'tyve';
  282.           break;
  283.  
  284.       case 1:
  285.           switch ($d) {
  286.           case 0:
  287.               $ret .= $this->_sep . 'ti';
  288.               break;
  289.  
  290.           case 1:
  291.               $ret .= $this->_sep . 'elleve';
  292.               break;
  293.  
  294.           case 2:
  295.               $ret .= $this->_sep . 'tolv';
  296.               break;
  297.  
  298.           case 3:
  299.               $ret .= $this->_sep . 'tretten';
  300.               break;
  301.  
  302.           case 4:
  303.               $ret .= $this->_sep . 'fjorten';
  304.               break;
  305.  
  306.           case 5:
  307.               $ret .= $this->_sep . 'femten';
  308.               break;
  309.  
  310.           case 6:
  311.               $ret .= $this->_sep . 'seksten';
  312.               break;
  313.  
  314.           case 7:
  315.               $ret .= $this->_sep . 'sytten';
  316.               break;
  317.  
  318.           case 8:
  319.               $ret .= $this->_sep . 'atten';
  320.               break;
  321.  
  322.           case 9:
  323.               $ret .= $this->_sep . 'nitten';
  324.               break;
  325.  
  326.           }
  327.           break;
  328.       }
  329.  
  330.       if ($power > 0) {
  331.         if (isset($this->_exponent[$power]))
  332.           $lev = $this->_exponent[$power];
  333.  
  334.         if (!isset($lev) || !is_array($lev))
  335.           return null;
  336.  
  337.         if ($d == 1 && ($t+$h) == 0) {
  338.           $ret .= $this->_sep . $lev[0];
  339.         } else {
  340.           $ret .= $this->_sep . $lev[1];
  341.         }
  342.       }
  343.  
  344.       if ($powsuffix != '')
  345.         $ret .= $this->_sep . $powsuffix;
  346.  
  347.       return $ret;
  348.     }
  349.     // }}}
  350.     // {{{ toCurrencyWords()
  351.  
  352.     /**
  353.      * Converts a currency value to its word representation
  354.      * (with monetary units) in danish language
  355.      *
  356.      * @param  integer $int_curr An international currency symbol
  357.      *                 as defined by the ISO 4217 standard (three characters)
  358.      * @param  integer $decimal A money total amount without fraction part (e.g. amount of dollars)
  359.      * @param  integer $fraction Fractional part of the money amount (e.g. amount of cents)
  360.      *                 Optional. Defaults to false.
  361.      * @param  integer $convert_fraction Convert fraction to words (left as numeric if set to false).
  362.      *                 Optional. Defaults to true.
  363.      *
  364.      * @return string  The corresponding word representation for the currency
  365.      *
  366.      * @access public
  367.      * @author Jesper Veggerby <pear.nosey@veggerby.dk>
  368.      * @since  Numbers_Words 0.4
  369.      */
  370.     function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = true) {
  371.         $int_curr = strtoupper($int_curr);
  372.         if (!isset($this->_currency_names[$int_curr])) {
  373.             $int_curr = $this->def_currency;
  374.         }
  375.         $curr_names = $this->_currency_names[$int_curr];
  376.  
  377.         if (($decimal != "") and ($decimal != 0)) {
  378.             $ret  = trim($this->toWords($decimal));
  379.             $lev  = ($decimal == 1) ? 0 : 1;
  380.             if ($lev > 0) {
  381.                 if (count($curr_names[0]) > 1) {
  382.                     $ret .= $this->_sep . $curr_names[0][$lev];
  383.                 } else {
  384.                     $ret .= $this->_sep . $curr_names[0][0];
  385.                 }
  386.             } else {
  387.                 $ret .= $this->_sep . $curr_names[0][0];
  388.             }
  389.  
  390.             if (($fraction !== false)  and ($fraction != 0)) {
  391.                 $ret .= $this->_sep . "og";
  392.             }
  393.         }
  394.  
  395.         if (($fraction !== false) and ($fraction != 0)) {
  396.             if ($convert_fraction) {
  397.                 $ret .= $this->_sep . trim($this->toWords($fraction));
  398.             } else {
  399.                 $ret .= $this->_sep . $fraction;
  400.             }
  401.             $lev  = ($fraction == 1) ? 0 : 1;
  402.             if ($lev > 0) {
  403.                 if (count($curr_names[1]) > 1) {
  404.                     $ret .= $this->_sep . $curr_names[1][$lev];
  405.                 } else {
  406.                     $ret .= $this->_sep . $curr_names[1][0];
  407.                 }
  408.             } else {
  409.                 $ret .= $this->_sep . $curr_names[1][0];
  410.             }
  411.         }
  412.         return $ret;
  413.     }
  414.     // }}}
  415.  }
  416.  
  417. ?>
  418.