Issues

ZF-8781: 31.40. Converting numerals from Latin script to Eastern Arabic script won't work

Description

Priority low, I search also myself. but I try the example 31.40. Converting numerals from Latin script to Eastern Arabic script.

converted value = null

see my script test here. http://xp-dev.com/sc/browse/…

Comments

I can't reproduce your problems.

The given code is not from the manual and example 31.40 works and returns arabic script.

Tried by using "de_AT" which returns 18 scripts and also by using "en" which also returns 18 scripts.

Can you provide us with a screenshot ?

ok so I've retry.



Zend_Locale::convertNumerals()

Zf : <?php echo Zend_Version::VERSION;?>

$locale = new Zend_Locale(); Zend_Debug::dump($locale->toString(), 'Locale'); echo '

Original script

'; $latinScript = '123'; $arabicScript = Zend_Locale_Format::convertNumerals($latinScript, 'Latn', 'Arab'); print "\nOriginal: " . $latinScript; print "\nLocalized: " . $arabicScript;

{quote} Zend_Locale::convertNumerals()

Zf : 1.9.6

Locale string(2) "fr"

Original script

Original: 123 Localized: {quote}

I continue to test myself.

Precision I use Windows. I would make check on iconv and preg_replace

{quote} iconv iconv support enabled iconv implementation "libiconv" iconv library version 1.9

Directive Local Value Master Value iconv.input_encoding ISO-8859-1 ISO-8859-1 iconv.internal_encoding ISO-8859-1 ISO-8859-1 iconv.output_encoding ISO-8859-1 ISO-8859-1


pcre PCRE (Perl Compatible Regular Expressions) Support enabled PCRE Library Version 7.9 2009-04-11

Directive Local Value Master Value pcre.backtrack_limit 100000 100000 pcre.recursion_limit 100000 100000 {quote}

problem is in both.


for ($x = 0; $x < 10; ++$x) {
            
            $asource[$x] = "/" . iconv_substr($source, $x, 1) . "/u";
            $atarget[$x] = iconv_substr($target, $x, 1);
        }

        
        return preg_replace($asource, $atarget, $input);

  $asource[] = "/٤/u";
  $asource[] = "/٣/u";
  $atarget[] = "x";
  $atarget[] = "y";

$input = '٣٤٥٦';
$z = preg_replace($asource, $atarget, $input);
Zend_Debug::dump($asource, '$asource');
Zend_Debug::dump($atarget, '$atarget');
Zend_Debug::dump($z, 'preg_replace');

$a = iconv_substr('1٣٤2٥٦  Tests', 2, 1);
Zend_Debug::dump($a, 'iconv');
echo ord($a);

{quote} $asource array(2) { [0] => string(5) "/٤/u" [1] => string(5) "/٣/u" }

$atarget array(2) { [0] => string(1) "x" [1] => string(1) "y" }

preg_replace string(6) "yx٥٦"

iconv string(1) "�" <--

ord -> 163

{quote}

I still don't know where your problems are, nor what you are getting for an output from the manual example, nor what you want to show with this code snippets.

PS: I also used Windows for reproduction. Default installation

I found a solution but it's in ZF code

in


  public static function convertNumerals($input, $from, $to = null)
    {
    
        $from   = strtolower($from);
        $source = Zend_Locale_Data::getContent('en', 'numberingsystem', $from);
        if (empty($source)) {
            require_once 'Zend/Locale/Exception.php';
            throw new Zend_Locale_Exception("Unknown script '$from'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9.");
        }

        if ($to !== null) {
            $to     = strtolower($to);
            $target = Zend_Locale_Data::getContent('en', 'numberingsystem', $to);
            if (empty($target)) {
                require_once 'Zend/Locale/Exception.php';
                throw new Zend_Locale_Exception("Unknown script '$to'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9.");
            }
        } else {
            $target = '0123456789';
        }

        for ($x = 0; $x < 10; ++$x) {
            
            $asource[$x] = "/" . iconv_substr($source, $x, 1) . "/u";
            $atarget[$x] = iconv_substr($target, $x, 1);
        }

        
        return preg_replace($asource, $atarget, $input);
    }

I just add 'UTF-8' as 4st param of iconv_substr

and all works fine.



  $asource[$x] = "/" . iconv_substr($source, $x, 1, 'UTF-8') . "/u";
            $atarget[$x] = iconv_substr($target, $x, 1, 'UTF-8');

{quote} I still don't know where your problems are, nor what you are getting for an output from the manual example, nor what you want to show with this code snippets. {quote}

OK, sorry.

I just want to show than on my Zend server install on winows

Zend_Locale_Format::convertNumerals return NULL

until I add , 'UTF-8' on 4st param of iconv_substr function. in Zend_Locale_Format::convertNumerals

Ok I just start my brain.


ini_set('iconv.internal_encoding', 'UTF-8');

before the sample and it's work. without change anything in zend framework. But I think it's better to change it.

I tell to continue to test most of example and complete them in my shared project. ZF_Experiences.

This clearifies why it does not work in your environment.

In my installation UTF-8 is set as default. It seems that within the server installation it is NOT default.

This issue was already fixed for the next minor release (1.10) a few months ago. See the linked issues.

Closing as duplicate.

You can use 1.10pre or trunk to have a fixed version.

Christophe: As said... this has already been fixed in past and it will be released with the next release. We can't throw out releases each two weeks ;-)