Source for file lang.bg.php
Documentation is available at lang.bg.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Kouber Saparev <kouber@saparev.com> |
// +----------------------------------------------------------------------+
require_once("Numbers/Words.php");
* Class for translating numbers into Bulgarian.
* @author Kouber Saparev <kouber@saparev.com>
* Language name in English.
* Some miscellaneous words and language constructs.
var $_misc_strings = array (
'edinadeset'=> , // "eleven"
'na'=> , // liaison particle for 12 to 19
'sta'=> , // suffix for 2 and 3 hundred
'stotin'=> , // suffix for 4 to 9 hundred
'hiliadi'=> // plural form of "thousand"
* The words for digits (except zero). Note that, there are three genders for them (neuter, masculine and feminine).
* The words for 3 to 9 (masculine) and for 2 to 9 (feminine) are the same as neuter, so they're filled
* in the _initDigits() method, which is invoked from the constructor.
0=>array (1=> , , , , , , , , ), // neuter
1=>array (1=> , ), // masculine
-1=>array (1=> ) // feminine
* A flag, that determines if the _digits array is filled for masculine and feminine genders.
var $_digits_initialized = false;
* A flag, that determines if the "and" word is placed already before the last non-empty group of digits.
* The word for the "and" language construct.
* The word for the minus sign.
var $_minus = ; // minus sign
* The plural suffix (except for thousand).
var $_plural = ; // plural suffix
* The suffixes for exponents (singular).
// {{{ Numbers_Words_bg()
* The class constructor, used for calling the _initDigits method.
* @author Kouber Saparev <kouber@saparev.com>
* @see function _initDigits
* Fills the _digits array for masculine and feminine genders with
* corresponding references to neuter words (when they're the same).
* @author Kouber Saparev <kouber@saparev.com>
if (!$this->_digits_initialized) {
for ($i=3; $i<=9; $i++ ) {
$this->_digits[1 ][$i] = & $this->_digits[0 ][$i];
for ($i=2; $i<=9; $i++ ) {
$this->_digits[-1 ][$i] = & $this->_digits[0 ][$i];
$this->_digits_initialized = true;
* Split a number to groups of three-digit numbers.
* @param mixed $num An integer or its string representation
* @return array Groups of three-digit numbers.
* @author Kouber Saparev <kouber@saparev.com>
function _splitNumber ($num)
$first = substr($num, 0 , $strlen%3 );
// {{{ _showDigitsGroup()
* Converts a three-digit number to its word representation
* @param integer $num An integer between 1 and 999 inclusive.
* @param integer $gender An integer which represents the gender of
* the current digits group.
* @param boolean $last A flag that determines if the current digits group
* @return string The words for the given number.
* @author Kouber Saparev <kouber@saparev.com>
function _showDigitsGroup ($num, $gender = 0 , $last = false )
/* A storage array for the return string.
Positions 1, 3, 5 are intended for digit words
and everything else (0, 2, 4) for "and" words.
Both of the above types are optional, so the size of
// extract the value of each digit from the three-digit number
$d = ($num- $e)%100/10; // tens
$s = ($num- $d*10- $e)%1000/100; // hundreds
// process the "hundreds" digit.
$ret[1 ] = $this->_misc_strings['sto'];
$ret[1 ] = $this->_digits[0 ][$s]. $this->_misc_strings['sta'];
$ret[1 ] = $this->_digits[0 ][$s]. $this->_misc_strings['stotin'];
// process the "tens" digit, and optionally the "ones" digit.
// in the case of 1, the "ones" digit also must be processed
$ret[3 ] = $this->_misc_strings['deset']; // ten
$ret[3 ] = $this->_misc_strings['edinadeset']; // eleven
$ret[3 ] = $this->_digits[1 ][$e]. $this->_misc_strings['na']. $this->_misc_strings['deset']; // twelve - nineteen
// the "ones" digit is alredy processed, so skip a second processment
$ret[3 ] = $this->_digits[1 ][$d]. $this->_misc_strings['deset']; // twenty - ninety
// process the "ones" digit
$ret[5 ] = $this->_digits[$gender][$e];
// put "and" where needed
// put "and" optionally in the case this is the last non-empty group
if (!$s|| count($ret)==1 ) {
// sort the return array so that "and" constructs go to theirs appropriate places
* Converts a number to its word representation
* @param integer $num An integer between 9.99*-10^302 and 9.99*10^302 (999 centillions)
* that need to be converted to words
* @return string The corresponding word representation
* @author Kouber Saparev <kouber@saparev.com>
// check if $num is a valid non-zero number
if (substr($num, 0 , 1 ) == '-') {
$ret_minus = $this->_minus . $this->_sep;
// if the absolute value is greater than 9.99*10^302, return infinity
return $ret_minus . $this->_infinity;
// strip excessive zero signs
// split $num to groups of three-digit numbers
$num_groups = $this->_splitNumber ($num);
$sizeof_numgroups = count($num_groups);
// go through the groups in reverse order, so that the last group could be determined
for ($i= $sizeof_numgroups-1 , $j=1; $i>=0; $i-- , $j++ ) {
// what is the corresponding exponent for the current group
$pow = $sizeof_numgroups- $i;
// skip processment for empty groups
if ($num_groups[$i]!= '000') {
$ret[$j] .= $this->_showDigitsGroup ($num_groups[$i], 0 , !$this->_last_and && $i). $this->_sep;
$ret[$j] .= $this->_exponent[($pow-1 )*3 ];
$ret[$j] .= $this->_showDigitsGroup ($num_groups[$i], -1 , !$this->_last_and && $i). $this->_sep;
$ret[$j] .= $this->_misc_strings['hiliadi']. $this->_sep;
$ret[$j] .= $this->_showDigitsGroup ($num_groups[$i], 1 , !$this->_last_and && $i). $this->_sep;
$ret[$j] .= $this->_exponent[($pow-1 )*3 ]. $this->_plural. $this->_sep;
$ret[$j] .= $this->_showDigitsGroup ($num_groups[$i], 0 , !$this->_last_and && $i). $this->_sep;
$ret[$j] .= $this->_exponent[($pow-1 )*3 ]. $this->_sep;
$ret[$j] .= $this->_digits[1 ][1 ]. $this->_sep. $this->_exponent[($pow-1 )*3 ]. $this->_sep;
Documentation generated on Mon, 11 Mar 2019 13:55:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|