Zend Framework

31.40. Converting numerals from Latin script to Eastern Arabic script won't work

Details

  • Type: Docs:  Problem Docs: Problem
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Duplicate
  • Affects Version/s: 1.9.6
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Locale
  • Labels:
    None
  • Language:
    French

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://www.xp-dev.com/sc/browse/66067/%2Ftrunk%2FZend_Locale%2FExemple.31.40.ConvertingNumeralsScriptLatin2EasternArabic.php

Issue Links

Activity

Hide
Thomas Weidner added a comment -

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 ?

Show
Thomas Weidner added a comment - 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 ?
Hide
Christophe Gesché added a comment -

ok so I've retry.

<h1>Zend_Locale::convertNumerals()</h1>
<p>Zf : <?php echo Zend_Version::VERSION;?></p>

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

echo '<h2>Original script</h2>';

$latinScript = '123';
$arabicScript = Zend_Locale_Format::convertNumerals($latinScript,
                                                    'Latn',
                                                    'Arab');

print "\nOriginal:  " . $latinScript;
print "\nLocalized: " . $arabicScript;

Zend_Locale::convertNumerals()

Zf : 1.9.6

Locale string(2) "fr"

Original script

Original: 123 Localized:

I continue to test myself.

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

Show
Christophe Gesché added a comment - ok so I've retry.
<h1>Zend_Locale::convertNumerals()</h1>
<p>Zf : <?php echo Zend_Version::VERSION;?></p>

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

echo '<h2>Original script</h2>';

$latinScript = '123';
$arabicScript = Zend_Locale_Format::convertNumerals($latinScript,
                                                    'Latn',
                                                    'Arab');

print "\nOriginal:  " . $latinScript;
print "\nLocalized: " . $arabicScript;
Zend_Locale::convertNumerals() Zf : 1.9.6 Locale string(2) "fr" Original script Original: 123 Localized:
I continue to test myself. Precision I use Windows. I would make check on iconv and preg_replace
Hide
Christophe Gesché added a comment -

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

Show
Christophe Gesché added a comment -
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
Hide
Christophe Gesché added a comment -

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);

$asource array(2)

Unknown macro: { [0] => string(5) "/٤/u" [1] => string(5) "/٣/u" }

$atarget array(2)

Unknown macro: { [0] => string(1) "x" [1] => string(1) "y" }

preg_replace string(6) "yx٥٦"

iconv string(1) "�" <--

ord -> 163

Show
Christophe Gesché added a comment - 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);
$asource array(2)
Unknown macro: { [0] => string(5) "/٤/u" [1] => string(5) "/٣/u" }
$atarget array(2)
Unknown macro: { [0] => string(1) "x" [1] => string(1) "y" }
preg_replace string(6) "yx٥٦" iconv string(1) "�" <-- ord -> 163
Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - 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
Hide
Christophe Gesché added a comment -

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');
Show
Christophe Gesché added a comment - 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');
Hide
Christophe Gesché added a comment -

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.

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

Show
Christophe Gesché added a comment -
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.
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
Hide
Christophe Gesché added a comment -

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.

Show
Christophe Gesché added a comment - 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.
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - You can use 1.10pre or trunk to have a fixed version.
Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - 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

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: