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.bg.php next >
Encoding:
PHP Script  |  2008-07-02  |  16.1 KB  |  506 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Kouber Saparev <kouber@php.net>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: lang.bg.php,v 1.4 2004/10/22 18:22:52 kouber Exp $
  20.  
  21. /**
  22.  * Include needed files
  23.  */
  24. require_once("Numbers/Words.php");
  25.  
  26. /**
  27.  * Class for translating numbers into Bulgarian.
  28.  *
  29.  * @author Kouber Saparev <kouber@php.net> 
  30.  * @package Numbers_Words
  31.  */
  32. class Numbers_Words_bg extends Numbers_Words
  33. {
  34.  
  35.     // {{{ properties
  36.  
  37.     /**
  38.      * Locale name.
  39.      * @var string
  40.      * @access public
  41.      */
  42.     var $locale      = 'bg';
  43.  
  44.     /**
  45.      * Language name in English.
  46.      * @var string
  47.      * @access public
  48.      */
  49.     var $lang        = 'Bulgarian';
  50.  
  51.     /**
  52.      * Native language name.
  53.      * @var string
  54.      * @access public
  55.      */
  56.     var $lang_native = '┴·δπα≡±ΩΦ';
  57.  
  58.     /**
  59.      * Some miscellaneous words and language constructs.
  60.      * @var string
  61.      * @access private
  62.      */
  63.     var $_misc_strings = array(
  64.         'deset'=>'Σσ±σ≥',           // "ten"
  65.         'edinadeset'=>'σΣΦφαΣσ±σ≥', // "eleven"
  66.         'na'=>'φα',                 // liaison particle for 12 to 19
  67.         'sto'=>'±≥ε',               // "hundred"
  68.         'sta'=>'±≥α',               // suffix for 2 and 3 hundred
  69.         'stotin'=>'±≥ε≥Φφ',         // suffix for 4 to 9 hundred
  70.         'hiliadi'=>'⌡Φδ ΣΦ'         // plural form of "thousand"
  71.     );
  72.  
  73.  
  74.     /**
  75.      * The words for digits (except zero). Note that, there are three genders for them (neuter, masculine and feminine).
  76.      * The words for 3 to 9 (masculine) and for 2 to 9 (feminine) are the same as neuter, so they're filled
  77.      * in the _initDigits() method, which is invoked from the constructor.
  78.      * @var string
  79.      * @access private
  80.      */
  81.     var $_digits = array(
  82.         0=>array(1=>"σΣφε", "ΣΓσ", "≥≡Φ", "≈σ≥Φ≡Φ", "∩σ≥", "°σ±≥", "±σΣσ∞", "ε±σ∞", "ΣσΓσ≥"), // neuter
  83.         1=>array(1=>'σΣΦφ', 'ΣΓα'),                                                           // masculine
  84.        -1=>array(1=>'σΣφα')                                                                   // feminine
  85.     );
  86.  
  87.     /**
  88.      * A flag, that determines if the _digits array is filled for masculine and feminine genders.
  89.      * @var string
  90.      * @access private
  91.      */
  92.     var $_digits_initialized = false;
  93.  
  94.     /**
  95.      * A flag, that determines if the "and" word is placed already before the last non-empty group of digits.
  96.      * @var string
  97.      * @access private
  98.      */
  99.     var $_last_and = false;
  100.  
  101.     /**
  102.      * The word for zero.
  103.      * @var string
  104.      * @access private
  105.      */
  106.     var $_zero = 'φ≤δα';
  107.  
  108.     /**
  109.      * The word for infinity.
  110.      * @var string
  111.      * @access private
  112.      */
  113.     var $_infinity = 'ßστΩ≡αΘφε±≥';
  114.  
  115.     /**
  116.      * The word for the "and" language construct.
  117.      * @var string
  118.      * @access private
  119.      */
  120.     var $_and = 'Φ';
  121.     
  122.     /**
  123.      * The word separator.
  124.      * @var string
  125.      * @access private
  126.      */
  127.     var $_sep = ' ';
  128.  
  129.     /**
  130.      * The word for the minus sign.
  131.      * @var string
  132.      * @access private
  133.      */
  134.     var $_minus = '∞Φφ≤±'; // minus sign
  135.  
  136.     /**
  137.      * The plural suffix (except for thousand).
  138.      * @var string
  139.      * @access private
  140.      */
  141.     var $_plural = 'α'; // plural suffix
  142.  
  143.     /**
  144.      * The suffixes for exponents (singular).
  145.      * @var array
  146.      * @access private
  147.      */
  148.     var $_exponent = array(
  149.           0 => '',
  150.           3 => '⌡Φδ Σα',
  151.           6 => '∞ΦδΦεφ',
  152.           9 => '∞ΦδΦα≡Σ',
  153.          12 => '≥≡ΦδΦεφ',
  154.          15 => 'ΩΓαΣ≡ΦδΦεφ',
  155.          18 => 'ΩΓΦφ≥ΦδΦεφ',
  156.          21 => '±σΩ±≥ΦδΦεφ',
  157.          24 => '±σ∩≥ΦδΦεφ',
  158.          27 => 'εΩ≥ΦδΦεφ',
  159.          30 => 'φεφαδΦεφ',
  160.          33 => 'ΣσΩαδΦεφ',
  161.          36 => '≤φΣσΩαδΦεφ',
  162.          39 => 'Σ≤εΣσΩαδΦεφ',
  163.          42 => '≥≡σΣσΩαδΦεφ',
  164.          45 => 'ΩΓα≥ε≡ΣσΩαδΦεφ',
  165.          48 => 'ΩΓΦφ≥ΣσΩαδΦεφ',
  166.          51 => '±σΩ±ΣσΩαδΦεφ',
  167.          54 => '±σ∩≥ΣσΩαδΦεφ',
  168.          57 => 'εΩ≥εΣσΩαδΦεφ',
  169.          60 => 'φεΓσ∞ΣσΩαδΦεφ',
  170.          63 => 'ΓΦπΦφ≥ΦδΦεφ',
  171.          66 => '≤φΓΦπΦφ≥ΦδΦεφ',
  172.          69 => 'Σ≤εΓΦπΦφ≥ΦδΦεφ',
  173.          72 => '≥≡σΓΦπΦφ≥ΦδΦεφ',
  174.          75 => 'ΩΓα≥ε≡ΓΦπΦφ≥ΦδΦεφ',
  175.          78 => 'ΩΓΦφΓΦπΦφ≥ΦδΦεφ',
  176.          81 => '±σΩ±ΓΦπΦφ≥ΦδΦεφ',
  177.          84 => '±σ∩≥σφΓΦπΦφ≥ΦδΦεφ',
  178.          87 => 'εΩ≥εΓΦπΦφ≥ΦδΦεφ',
  179.          90 => 'φεΓσ∞ΓΦπΦφ≥ΦδΦεφ',
  180.          93 => '≥≡ΦπΦφ≥ΦδΦεφ',
  181.          96 => '≤φ≥≡ΦπΦφ≥ΦδΦεφ',
  182.          99 => 'Σ≤ε≥≡ΦπΦφ≥ΦδΦεφ',
  183.         102 => '≥≡σ≥≡ΦπΦφ≥ΦδΦεφ',
  184.         105 => 'ΩΓα≥ε≡≥≡ΦπΦφ≥ΦδΦεφ',
  185.         108 => 'ΩΓΦφ≥≡ΦπΦφ≥ΦδΦεφ',
  186.         111 => '±σΩ±≥≡ΦπΦφ≥ΦδΦεφ',
  187.         114 => '±σ∩≥σφ≥≡ΦπΦφ≥ΦδΦεφ',
  188.         117 => 'εΩ≥ε≥≡ΦπΦφ≥ΦδΦεφ',
  189.         120 => 'φεΓσ∞≥≡ΦπΦφ≥ΦδΦεφ',
  190.         123 => 'ΩΓαΣ≡απΦφ≥ΦδΦεφ',
  191.         126 => '≤φΩΓαΣ≡απΦφ≥ΦδΦεφ',
  192.         129 => 'Σ≤εΩΓαΣ≡απΦφ≥ΦδΦεφ',
  193.         132 => '≥≡σΩΓαΣ≡απΦφ≥ΦδΦεφ',
  194.         135 => 'ΩΓα≥ε≡ΩΓαΣ≡απΦφ≥ΦδΦεφ',
  195.         138 => 'ΩΓΦφΩΓαΣ≡απΦφ≥ΦδΦεφ',
  196.         141 => '±σΩ±ΩΓαΣ≡απΦφ≥ΦδΦεφ',
  197.         144 => '±σ∩≥σφΩΓαΣ≡απΦφ≥ΦδΦεφ',
  198.         147 => 'εΩ≥εΩΓαΣ≡απΦφ≥ΦδΦεφ',
  199.         150 => 'φεΓσ∞ΩΓαΣ≡απΦφ≥ΦδΦεφ',
  200.         153 => 'ΩΓΦφΩΓαπΦφ≥ΦδΦεφ',
  201.         156 => '≤φΩΓΦφΩαπΦφ≥ΦδΦεφ',
  202.         159 => 'Σ≤εΩΓΦφΩαπΦφ≥ΦδΦεφ',
  203.         162 => '≥≡σΩΓΦφΩαπΦφ≥ΦδΦεφ',
  204.         165 => 'ΩΓα≥ε≡ΩΓΦφΩαπΦφ≥ΦδΦεφ',
  205.         168 => 'ΩΓΦφΩΓΦφΩαπΦφ≥ΦδΦεφ',
  206.         171 => '±σΩ±ΩΓΦφΩαπΦφ≥ΦδΦεφ',
  207.         174 => '±σ∩≥σφΩΓΦφΩαπΦφ≥ΦδΦεφ',
  208.         177 => 'εΩ≥εΩΓΦφΩαπΦφ≥ΦδΦεφ',
  209.         180 => 'φεΓσ∞ΩΓΦφΩαπΦφ≥ΦδΦεφ',
  210.         183 => '±σΩ±απΦφ≥ΦδΦεφ',
  211.         186 => '≤φ±σΩ±απΦφ≥ΦδΦεφ',
  212.         189 => 'Σ≤ε±σΩ±απΦφ≥ΦδΦεφ',
  213.         192 => '≥≡σ±σΩ±απΦφ≥ΦδΦεφ',
  214.         195 => 'ΩΓα≥ε≡±σΩ±απΦφ≥ΦδΦεφ',
  215.         198 => 'ΩΓΦφ±σΩ±απΦφ≥ΦδΦεφ',
  216.         201 => '±σΩ±±σΩ±απΦφ≥ΦδΦεφ',
  217.         204 => '±σ∩≥σφ±σΩ±απΦφ≥ΦδΦεφ',
  218.         207 => 'εΩ≥ε±σΩ±απΦφ≥ΦδΦεφ',
  219.         210 => 'φεΓσ∞±σΩ±απΦφ≥ΦδΦεφ',
  220.         213 => '±σ∩≥απΦφ≥ΦδΦεφ',
  221.         216 => '≤φ±σ∩≥απΦφ≥ΦδΦεφ',
  222.         219 => 'Σ≤ε±σ∩≥απΦφ≥ΦδΦεφ',
  223.         222 => '≥≡σ±σ∩≥απΦφ≥ΦδΦεφ',
  224.         225 => 'ΩΓα≥ε≡±σ∩≥απΦφ≥ΦδΦεφ',
  225.         228 => 'ΩΓΦφ±σ∩≥απΦφ≥ΦδΦεφ',
  226.         231 => '±σΩ±±σ∩≥απΦφ≥ΦδΦεφ',
  227.         234 => '±σ∩≥σφ±σ∩≥απΦφ≥ΦδΦεφ',
  228.         237 => 'εΩ≥ε±σ∩≥απΦφ≥ΦδΦεφ',
  229.         240 => 'φεΓσ∞±σ∩≥απΦφ≥ΦδΦεφ',
  230.         243 => 'εΩ≥επΦφ≥ΦδΦεφ',
  231.         246 => '≤φεΩ≥επΦφ≥ΦδΦεφ',
  232.         249 => 'Σ≤εεΩ≥επΦφ≥ΦδΦεφ',
  233.         252 => '≥≡σεΩ≥επΦφ≥ΦδΦεφ',
  234.         255 => 'ΩΓα≥ε≡εΩ≥επΦφ≥ΦδΦεφ',
  235.         258 => 'ΩΓΦφεΩ≥επΦφ≥ΦδΦεφ',
  236.         261 => '±σΩ±εΩ≥επΦφ≥ΦδΦεφ',
  237.         264 => '±σ∩≥εΩ≥επΦφ≥ΦδΦεφ',
  238.         267 => 'εΩ≥εεΩ≥επΦφ≥ΦδΦεφ',
  239.         270 => 'φεΓσ∞εΩ≥επΦφ≥ΦδΦεφ',
  240.         273 => 'φεφαπΦφ≥ΦδΦεφ',
  241.         276 => '≤φφεφαπΦφ≥ΦδΦεφ',
  242.         279 => 'Σ≤εφεφαπΦφ≥ΦδΦεφ',
  243.         282 => '≥≡σφεφαπΦφ≥ΦδΦεφ',
  244.         285 => 'ΩΓα≥ε≡φεφαπΦφ≥ΦδΦεφ',
  245.         288 => 'ΩΓΦφφεφαπΦφ≥ΦδΦεφ',
  246.         291 => '±σΩ±φεφαπΦφ≥ΦδΦεφ',
  247.         294 => '±σ∩≥σφφεφαπΦφ≥ΦδΦεφ',
  248.         297 => 'εΩ≥εφεφαπΦφ≥ΦδΦεφ',
  249.         300 => 'φεΓσ∞φεφαπΦφ≥ΦδΦεφ',
  250.         303 => '÷σφ≥ΦδΦεφ'
  251.     );
  252.     // }}}
  253.  
  254.     // {{{ Numbers_Words_bg()
  255.  
  256.     /**
  257.      * The class constructor, used for calling the _initDigits method.
  258.      *
  259.      * @return void
  260.      *
  261.      * @access public
  262.      * @author Kouber Saparev <kouber@php.net>
  263.      * @see function _initDigits
  264.      */
  265.     function Numbers_Words_bg() {
  266.         $this->_initDigits();
  267.     }
  268.     // }}}
  269.  
  270.     // {{{ _initDigits()
  271.  
  272.     /**
  273.      * Fills the _digits array for masculine and feminine genders with
  274.      * corresponding references to neuter words (when they're the same).
  275.      *
  276.      * @return void
  277.      *
  278.      * @access private
  279.      * @author Kouber Saparev <kouber@php.net>
  280.      */
  281.     function _initDigits() {
  282.         if (!$this->_digits_initialized) {
  283.             for ($i=3; $i<=9; $i++) {
  284.                 $this->_digits[1][$i] =& $this->_digits[0][$i];
  285.             }
  286.             for ($i=2; $i<=9; $i++) {
  287.                 $this->_digits[-1][$i] =& $this->_digits[0][$i];
  288.             }
  289.             $this->_digits_initialized = true;
  290.         }
  291.     }
  292.     // }}}
  293.  
  294.     // {{{ _splitNumber()
  295.  
  296.     /**
  297.      * Split a number to groups of three-digit numbers.
  298.      *
  299.      * @param  mixed  $num   An integer or its string representation
  300.      *                       that need to be split
  301.      *
  302.      * @return array  Groups of three-digit numbers.
  303.      *
  304.      * @access private
  305.      * @author Kouber Saparev <kouber@php.net>
  306.      * @since  PHP 4.2.3
  307.      */
  308.  
  309.     function _splitNumber($num)
  310.     {
  311.         if (is_string($num)) {
  312.             $ret = array();
  313.             $strlen = strlen($num);
  314.             $first = substr($num, 0, $strlen%3);
  315.             preg_match_all('/\d{3}/', substr($num, $strlen%3, $strlen), $m);
  316.             $ret =& $m[0];
  317.             if ($first) array_unshift($ret, $first);
  318.             return $ret;
  319.         }
  320.         else
  321.             return explode(' ', number_format($num, 0, '', ' ')); // a faster version for integers
  322.     }
  323.     // }}}
  324.  
  325.     // {{{ _showDigitsGroup()
  326.  
  327.     /**
  328.      * Converts a three-digit number to its word representation
  329.      * in Bulgarian language.
  330.      *
  331.      * @param  integer  $num     An integer between 1 and 999 inclusive.
  332.      *
  333.      * @param  integer  $gender  An integer which represents the gender of
  334.      *                                                     the current digits group.
  335.      *                                                     0 - neuter
  336.      *                                                     1 - masculine
  337.      *                                                    -1 - feminine
  338.      *
  339.      * @param  boolean  $last    A flag that determines if the current digits group
  340.      *                           is the last one.
  341.      *
  342.      * @return string   The words for the given number.
  343.      *
  344.      * @access private
  345.      * @author Kouber Saparev <kouber@php.net>
  346.      */
  347.     function _showDigitsGroup($num, $gender = 0, $last = false)
  348.     {
  349.         /* A storage array for the return string.
  350.              Positions 1, 3, 5 are intended for digit words
  351.              and everything else (0, 2, 4) for "and" words.
  352.              Both of the above types are optional, so the size of
  353.              the array may vary.
  354.         */
  355.         $ret = array();
  356.         
  357.         // extract the value of each digit from the three-digit number
  358.         $e = $num%10;                  // ones
  359.         $d = ($num-$e)%100/10;         // tens
  360.         $s = ($num-$d*10-$e)%1000/100; // hundreds
  361.         
  362.         // process the "hundreds" digit.
  363.         if ($s) {
  364.             switch ($s) {
  365.                 case 1:
  366.                     $ret[1] = $this->_misc_strings['sto'];
  367.                     break;
  368.                 case 2:
  369.                 case 3:
  370.                     $ret[1] = $this->_digits[0][$s].$this->_misc_strings['sta'];
  371.                     break;
  372.              default:
  373.                  $ret[1] = $this->_digits[0][$s].$this->_misc_strings['stotin'];
  374.             }
  375.         }
  376.  
  377.         // process the "tens" digit, and optionally the "ones" digit.
  378.         if ($d) {
  379.             // in the case of 1, the "ones" digit also must be processed
  380.             if ($d==1) {
  381.                 if (!$e) {
  382.                     $ret[3] = $this->_misc_strings['deset']; // ten
  383.                 } else {
  384.                     if ($e==1) {
  385.                         $ret[3] = $this->_misc_strings['edinadeset']; // eleven
  386.                     } else {
  387.                         $ret[3] = $this->_digits[1][$e].$this->_misc_strings['na'].$this->_misc_strings['deset']; // twelve - nineteen
  388.                     }
  389.                     // the "ones" digit is alredy processed, so skip a second processment
  390.                     $e = 0;
  391.                 }
  392.             } else {
  393.                 $ret[3] = $this->_digits[1][$d].$this->_misc_strings['deset']; // twenty - ninety
  394.             }
  395.         }
  396.  
  397.         // process the "ones" digit
  398.         if ($e) {
  399.             $ret[5] = $this->_digits[$gender][$e];
  400.         }
  401.  
  402.         // put "and" where needed
  403.         if (count($ret)>1) {
  404.             if ($e) {
  405.                 $ret[4] = $this->_and;
  406.             } else {
  407.                 $ret[2] = $this->_and;
  408.             }
  409.         }
  410.  
  411.         // put "and" optionally in the case this is the last non-empty group
  412.         if ($last) {
  413.             if (!$s||count($ret)==1) {
  414.                 $ret[0] = $this->_and;
  415.             }
  416.             $this->_last_and = true;
  417.         }
  418.  
  419.         // sort the return array so that "and" constructs go to theirs appropriate places
  420.         ksort($ret);
  421.  
  422.         return implode($this->_sep, $ret);
  423.     }
  424.     // }}}
  425.  
  426.     // {{{ toWords()
  427.  
  428.     /**
  429.      * Converts a number to its word representation
  430.      * in Bulgarian language.
  431.      *
  432.      * @param  integer $num   An integer between 9.99*-10^302 and 9.99*10^302 (999 centillions)
  433.      *                        that need to be converted to words
  434.      *
  435.      * @return string  The corresponding word representation
  436.      *
  437.      * @access public
  438.      * @author Kouber Saparev <kouber@php.net>
  439.      */
  440.     function toWords($num = 0)
  441.     {
  442.         $ret = array();
  443.         $ret_minus = '';
  444.  
  445.         // check if $num is a valid non-zero number
  446.         if (!$num || preg_match('/^-?0+$/', $num) || !preg_match('/^-?\d+$/', $num)) return $this->_zero;
  447.  
  448.         // add a minus sign
  449.         if (substr($num, 0, 1) == '-') {
  450.             $ret_minus = $this->_minus . $this->_sep;
  451.             $num = substr($num, 1);
  452.         }
  453.  
  454.         // if the absolute value is greater than 9.99*10^302, return infinity
  455.         if (strlen($num)>306) {
  456.             return $ret_minus . $this->_infinity;
  457.         }
  458.  
  459.         // strip excessive zero signs
  460.         $num = ltrim($num, '0');
  461.  
  462.         // split $num to groups of three-digit numbers
  463.         $num_groups = $this->_splitNumber($num);
  464.  
  465.         $sizeof_numgroups = count($num_groups);
  466.  
  467.         // go through the groups in reverse order, so that the last group could be determined
  468.         for ($i=$sizeof_numgroups-1, $j=1; $i>=0; $i--, $j++) {
  469.             if (!isset($ret[$j])) {
  470.                 $ret[$j] = '';
  471.             }
  472.  
  473.             // what is the corresponding exponent for the current group
  474.             $pow = $sizeof_numgroups-$i;
  475.  
  476.             // skip processment for empty groups
  477.             if ($num_groups[$i]!='000') {
  478.                 if ($num_groups[$i]>1) {
  479.                     if ($pow==1) {
  480.                         $ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 0, !$this->_last_and && $i).$this->_sep;
  481.                         $ret[$j] .= $this->_exponent[($pow-1)*3];
  482.                     } elseif ($pow==2) {
  483.                         $ret[$j] .= $this->_showDigitsGroup($num_groups[$i], -1, !$this->_last_and && $i).$this->_sep;
  484.                         $ret[$j] .= $this->_misc_strings['hiliadi'].$this->_sep;
  485.                     } else {
  486.                         $ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 1, !$this->_last_and && $i).$this->_sep;
  487.                         $ret[$j] .= $this->_exponent[($pow-1)*3].$this->_plural.$this->_sep;
  488.                     }
  489.                 } else {
  490.                     if ($pow==1) {
  491.                         $ret[$j] .= $this->_showDigitsGroup($num_groups[$i], 0, !$this->_last_and && $i).$this->_sep;
  492.                     } elseif ($pow==2) {
  493.                         $ret[$j] .= $this->_exponent[($pow-1)*3].$this->_sep;
  494.                     } else {
  495.                         $ret[$j] .= $this->_digits[1][1].$this->_sep.$this->_exponent[($pow-1)*3].$this->_sep;
  496.                     }
  497.                 }
  498.             }
  499.         }
  500.  
  501.         return $ret_minus . rtrim(implode('', array_reverse($ret)), $this->_sep);
  502.     }
  503.     // }}}
  504. }
  505. ?>
  506.