EzDevInfo.com

intl

A PHP 5.4+ internationalization library, powered by CLDR data.

Trouble installing PHP 5.3.0 with intl-support

Currently I'm trying to install PHP 5.3.0 on some Linux testing server. As we've urgently waited for ext/intl we want to check out the features it provides. I'm running configure successfully with the following arguments

./configure
    --with-apxs2=/usr/local/apache2/bin/apxs
    --prefix=/usr/local/php
    --with-zlib-dir=/usr/local/zlib
    --with-imap=/.../imap-2006k
    --with-imap-ssl
    --with-openssl=shared
    --with-iconv=shared
    --with-zlib=shared
    --with-curl=shared
    --with-curlwrappers
    --enable-exif
    --with-ldap=shared,/usr/local/openldap
    --with-ldap-sasl
    --enable-mbstring=shared
    --with-mcrypt
    --enable-soap=shared
    --enable-sockets
    --enable-zip=shared
    --enable-pdo=shared
    --with-pdo-sqlite=shared
    --with-sqlite=shared
    --with-mysql=shared,/usr/local/mysql
    --with-pdo-mysql=shared,/usr/local/mysql
    --with-mysqli=shared,/usr/local/mysql/bin/mysql_config
    --with-mhash=shared,/usr/local/mhash
    --with-libxml-dir=/usr/local/libxml2
    --with-xsl=shared,/usr/local/libxslt
    --enable-xmlreader=shared
    --enable-xmlwriter=shared
    --with-gmp=shared
    --with-icu-dir=/usr/local/icu
    --enable-intl

ICU 4.2 is located at /usr/local/icu and PHP 5.2.9 compiled flawlessly (without the int- and icu-options). But when I complie the PHP 5.3.0 source I get a whole lot of error messages of the kind

ext/intl/grapheme/.libs/grapheme_util.o(.text+0xbab):/.../php-5.3.0/ext/intl/grapheme/grapheme_util.c:208: undefined reference to `ubrk_close_4_2'

I'm quite sure it has something to do with not finding the shared libraries. Setting

export LD_LIBRARY_PATH=/usr/local/icu/lib

doesn't help.

Can anyone point me to some solution? I'm rather clueless - and I'm no real expert in these things...

EDIT:

I just rechecked and made sure that the various icu-libraries and the respective soft links are all located in /usr/local/icu/lib:

lrwxrwxrwx  1 root root       20 Jul  1 09:56 libicudata.so -> libicudata.so.42.0.1
lrwxrwxrwx  1 root root       20 Jul  1 09:56 libicudata.so.42 -> libicudata.so.42.0.1
-rw-r--r--  1 root root 16015140 Jul  1 09:56 libicudata.so.42.0.1
lrwxrwxrwx  1 root root       20 Jul  1 09:56 libicui18n.so -> libicui18n.so.42.0.1
lrwxrwxrwx  1 root root       20 Jul  1 09:56 libicui18n.so.42 -> libicui18n.so.42.0.1
-rwxr-xr-x  1 root root  2454770 Jul  1 09:56 libicui18n.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicuio.so -> libicuio.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicuio.so.42 -> libicuio.so.42.0.1
-rwxr-xr-x  1 root root    65299 Jul  1 09:56 libicuio.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicule.so -> libicule.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicule.so.42 -> libicule.so.42.0.1
-rwxr-xr-x  1 root root   356125 Jul  1 09:56 libicule.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libiculx.so -> libiculx.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libiculx.so.42 -> libiculx.so.42.0.1
-rwxr-xr-x  1 root root    75110 Jul  1 09:56 libiculx.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicutu.so -> libicutu.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicutu.so.42 -> libicutu.so.42.0.1
-rwxr-xr-x  1 root root   159330 Jul  1 09:56 libicutu.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicuuc.so -> libicuuc.so.42.0.1
lrwxrwxrwx  1 root root       18 Jul  1 09:56 libicuuc.so.42 -> libicuuc.so.42.0.1
-rwxr-xr-x  1 root root  1660769 Jul  1 09:56 libicuuc.so.42.0.1

make check runs tons of tests - all of them successfully:

[All tests passed successfully...]
Elapsed Time: 00:00:25.000
make[2]: Leaving directory `/.../icu-4.2/source/test/cintltst'
---------------
ALL TESTS SUMMARY:
All tests OK:  testdata intltest iotest cintltst
make[1]: Leaving directory `/.../icu-4.2/source/test'
make[1]: Entering directory `/.../icu-4.2/source'
verifying that icu-config --selfcheck can operate
verifying that make -f Makefile.inc selfcheck can operate
PASS: config selfcheck OK
make[1]: Leaving directory `/.../icu-4.2/source'

EDIT: answers to VolkerK's questions

I installed ICU 4.2 from source and as I wrote above the build process, the unit-tests and the installation all went fine.

/usr/local/icu/bin/icu-config --version
4.2.0.1

/usr/local/icu/bin/icu-config --prefix
/usr/local/icu

/usr/local/icu/bin/icu-config --cppflags-searchpath
-I/usr/local/icu/include

/usr/local/icu/bin/icu-config --ldflags --ldflags-icuio
-lpthread -lm   -L/usr/local/icu/lib -licui18n -licuuc -licudata  -lpthread -lm   -licuio

objdump -C /usr/local/icu/lib/libicuuc.so.42.0.1
// doesn't work because of unrecognized argument -C

EDIT regarding VolkerK's comment:

No, there has been no switch of the compiler involved - I ran both build processes directly one after the other. objdump /usr/local/icu/lib/libicuuc.so.42.0.1 doesn't work either but I managed to run

objdump -t /usr/local/icu/lib/libicuuc.so.42.0.1 | grep ubrk_close
00000000000d2484 g     F .text  000000000000002d              ubrk_close_4_2

Don't know if this information can help.

EDIT on VolkerK's edit1 and edit2:

I think there's the rub - there is indeed another icu-version on the sytem; at least in parts (there is no other icu-config for example; only the one in /usr/local/icu/bin).

gcc -lpthread -lm -L/usr/local/icu/lib -licui18n -licuuc -licudata -lpthread -lm -licuio -print-file-name=libicuuc.so returns

/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../lib64/libicuuc.so

while gcc -lpthread -lm -L/usr/local/icu/lib -licui18n -licuuc -licudata -lpthread -lm -licuio -print-file-name=libicuuc.so.42 returns

libicuuc.so.42

So the problem seems to be, how to get the new lib-path into the build process?? By the way, I learned a lot from your answers - thank's to all of you.

I also tried to compile your simple test program - and it also fails with the same undefined reference error, most likely due to the same reason PHP won't compile.

How can I get rid of the reference to the old icu-library in the lib-path or how do I prioritize the new icu-library-path?


Source: (StackOverflow)

Producing lists in Intl/ICU with PHP

I'm using PHP 5.3's Intl extension for formatting strings on my website. However, I have happened upon a string that requires a list of items. The list given to the website can be any number of items, and should appear in however the language renders lists. In English, it would appear as "a, b, c, and d" or "a, b, c, d, e, f, g, and h". Rendering this English form is easy enough, but I don't know if this is a generic, international way of producing lists (I would bet that it isn't). Is there some way to do this with the intl extension, or ICU formatting?


Source: (StackOverflow)

Advertisements

Can't get to install 'intl' extension for php on debian

I have a debian server and I want to install the "intl" extension through pecl.

During the installation it asks me: "Specify where ICU libraries and headers can be found [DEFAULT] :" Here I've been trying several options, including leaving it empty to use DEFAULT, but I get the following error:

configure: error: C++ preprocessor "/lib/cpp" fails sanity check See config.log' for more details. ERROR:/tmp/pear/temp/intl/configure --with-icu-dir=DEFAULT' failed

I've installed php5.3 with: make && make install. I have already installed "icu", but unlike php5.3, it was installed with apt-get (i don't know if this is important).

Any idea?


Source: (StackOverflow)

PHP NumberFormatter and Currency, can't set precision

I want to set a precision of 0 when using the NumberFormatter PHP class (from Intl extension) with currency. However I've got some strange result. Here:

$numberFormatter = new NumberFormatter('en-US', NumberFormatter::CURRENCY);
$numberFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);

echo $numberFormatter->formatCurrency('45', 'USD');

It outputs $45, which is what I want. However, if I change the currency to EUR with the same settings:

echo $numberFormatter->formatCurrency('45', 'EUR');

It outputs €45.00 (although I explicitly set to have a precision of zero).

Even more strange, if I set the locale to fr-FR, it outputs the number as expected:

$numberFormatter = new NumberFormatter('fr-FR', NumberFormatter::CURRENCY);
$numberFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);

echo $numberFormatter->formatCurrency('45', 'EUR');

It outputs 45 €.

Is this a bug?


Source: (StackOverflow)

IntlDateFormatter::format(): datefmt_format: takes either an array or an integer timestamp value or a DateTime object (SonataSanBox) [closed]

I have installed SonataAdmin Bundle. All is working fine but, when I add any user from dashboard, it throws a warning:

Warning: IntlDateFormatter::format(): datefmt_format: takes either an array or an integer timestamp value or a DateTime object in C:\wamp\www\sonata-sandbox\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 260


Source: (StackOverflow)

List of available collators in PHP?

I am considering using collators in PHP (I am no expert in PHP). Is there a way to know/list all collators available in PHP? I am looking for something similar to Java's Collator.getAvailableLocales(). Thanks.


Source: (StackOverflow)

Get CLDR information from Intl extention in php

I used Zend_Locale before but it's seems PHP intl extension have cldr information.

I need to get some info like get available countries for each language? for example en has US, UK, GB and fa has IR and AF and more data available on CLDR project.

Name of countries, list of timezones by each languages and more data exist on CLDR xml files.

It's embedded on php intl or i can download and bind them to class or method on it?

Which object or method give me this information on PHP intl extension?

CLDR information


Source: (StackOverflow)

gettext() equivalent in Intl library?

I'm looking for a way to to do i18n and l10n.

I've used gettext before and it was good: I would simply create .mo files in different languages and everything that needed to be translated would be in this notation:

echo __('string to be translated');

I know that there is Intl library built into PHP now, and I've been told that I should use it instead of gettext().

After reading through everything there is about Intl on php.net, I see that it has some nice features like locale handling, string comparison, number formatting, etc.

What I can't figure out is how I would handle regular string to string translation using Intl library. Any ideas?


Source: (StackOverflow)

PHP NumberFormatter Slovenian spellout wrong

I am trying to spellout an integer amount into Slovenian words (for postal declarations) using the NumberFormatter class from the intl package, but the result is completely wrong and makes no sense.

$fmt = new NumberFormatter('sl', NumberFormatter::SPELLOUT);
$fmt->format(561);

Results in "petsto šestdeset ena" while it should be "petsto enainšestdeset". Looks like baby talk instead.

In Croatian language, which is pretty similar, the result seems ok ("petsto šezdeset i jedan").

Is this a poorly done translation in PHP or is this based on my system locale? I'm on PHP 5.3.10 / Ubuntu 12.04.

EDIT:

intl is version 1.1.0, the current is 3.0.0, so maybe it has been fixed?


Source: (StackOverflow)

How can I change NumberFormatter::parseCurrency() behavior of accepting white space and non breaking space?

I'm trying to parse localized currency strings to currency and float value.

Everything works well for a while, now we experiencing some problems. It seems that NumberFormatter::parseCurrency uses an additional invisible character:

Testcode:

<?php
$formatter = new NumberFormatter("de_DE", NumberFormatter::CURRENCY);
var_dump(array(
    $formatter->parseCurrency("88,22 €", $curr), // taken from output of $formatter->format(88.22)
    $formatter->parseCurrency("88,22 €", $curr), // input with keyboard
    $formatter->parseCurrency("88,22 \xE2\x82\xAc", $curr), // just a test
    $formatter->format(88.22),
    "88,22 €" // keyboard input
));

Output:

array(5) {
  [0]=> float(88,22)
  [1]=> bool(false)
  [2]=> bool(false)
  [3]=> string(10) "88,22 €" // this as input works
  [4]=> string(9) "88,22 €" // this not...
}

As you can see, there is a difference in string length of output 3 and 4.

I get same results in PHP 5.3 (ubuntu with mbstring enabled) and 5.4 (Zend Server on Mac OS X).

The main problem is, input values from my form (ZF1 Application) are equally to output with index 4...

any suggestions? thanks in advance

Edit1:

hexdump of working value:

00000000  38 38 2c 32 32 c2 a0 e2  82 ac 0a                 |88,22......|
0000000b

hexdump of non working value:

00000000  38 38 2c 32 32 20 e2 82  ac 0a                    |88,22 ....|
0000000a

Edit2:

It seems to be a problem with the used whitepsace. c2 a0 is NO-BREAK SPACE and (maybe?) required by NumberFormatter::parseCurrency(). but 0x20 is the default space (which is entered in the input form). Current workaround is replacing the whitespace with NO-BREAK SPACE with $value = str_replace("\x20", "\xC2\xA0", $value);

Edit3:

On another System (Mac OS X with Zend Server 5.6, mbstring enabled, PHP 5.3.14) everything works as expected:

array(5) {
  [0]=> float(88,22)
  [1]=> float(88,22)
  [2]=> float(88,22)
  [3]=> string(9) "88,22 €"
  [4]=> string(9) "88,22 €"
}

Edit4:

The main difference between working with space and working with non break space configuration is the ICU version:

working version:

intl

Internationalization support => enabled
version => 1.1.0
ICU version => 3.8.1

Directive => Local Value => Master Value
intl.default_locale => no value => no value
intl.error_level => 0 => 0

not working version:

intl

Internationalization support => enabled
version => 1.1.0
ICU version => 4.8.1.1
ICU Data version => 4.8.1

Directive => Local Value => Master Value
intl.default_locale => no value => no value
intl.error_level => 0 => 0

Source: (StackOverflow)

PHP 5.3 seems to be missing Intl extension by default

My system is Ubuntu 12.04, PHP 5.3, and I'm trying to run some basic Intl code like this:

<?php
$coll  = collator_create('en_US');
$result = collator_compare($coll, "string#1", "string#2");

and it outputs

PHP Fatal error:  Call to undefined function collator_create()

Wasn't Intl extension supposed to be bundled with PHP since version 5.3?

PHP was installed via apt-get with this command line (I don't use Apache):

apt-get install php5 php5-cli php5-mysql php5-cgi php5-fpm php5-curl php-apc php5-memcache php5-memcached php5-common php5-gd php-xml-parser php-pear php5-imap php5-mcrypt php5-xdebug php5-suhosin

And here is what php -v produces:

PHP 5.3.10-1ubuntu3.5 with Suhosin-Patch (cli) (built: Jan 18 2013 23:40:19) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
    with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH

Source: (StackOverflow)

NumberFormatter::SPELLOUT spellout-ordinal in russian and italian

this code works for english, spanish and german ordninal numbers, but with russian or italian ordninal numbers it doesn't work.

'ru-RU','it-IT' also don't work

I get for example in russian for 2 -> два (this is the cardinal number) , but I want the ordinal number and this would be here 2 -> второй.

I get for example in italian for 2 -> due (this is the cardinal number) , but I want the ordinal number and this would be here 2 -> secondo.

Update:

I found a solution with works in french, spain, german and some other languages:

maskuline ordinal numbers: %spellout-ordinal-maskuline

feminine ordinal numbers: %spellout-ordinal-feminine

russian and italian version doesn't work and I tried already with -maskuline/-feminine

`$ru_ordinal = new NumberFormatter('ru', NumberFormatter::SPELLOUT);`
`$ru_ordinal->setTextAttribute(NumberFormatter::DEFAULT_RULESET,
                         "%spellout-ordinal");`  

Source: (StackOverflow)

PHP date format with intl-aware day suffix?

Sorry if this is a dupe - lots of similar questions but obviously if I could find an exact answer I wouldn't be asking :)

Note I'm coming from .Net and am a PHP newbie, so there may be noob-scale errors.

I would like to be able to output e.g. new DateTime('2014-01-01 13:15:00') as: 'Wednesday the 1st of January 2014 at 1:15PM' (possible - non-localized) or 'Mercredi 1er Janvier 2014 à 13h15' (not possible?).

Basically, there seems to be no ISO formatting equivalent to PHP's 'S' date format specifier, nor is there one for strftime?

The IntlDateFormatter::FULL comes close - but 'Wednesday, 1 January' or 'mercredi 1 janvier' is not good English (or French) - but it seems to be the closest that I can get? I could live without the 'on', 'the' and 'at' if I had to, but ordinal suffixes would be nice. ('Wednesday one January' - what's that, the beginning to a poem?)

I did see one example on the strftime section comments on PHP.net addressing this issue (which seems to suggest that it is an issue) - however it only seemed to add the English suffixes, which didn't seem much use? I'd like a simple method that takes a UTC datetime, a locale and a timezone and outputs a localized string - preferably in 'proper' human-readable format (as above) as is possible in English. I'd like to achieve this without writing a format string for every language in the world. It would also be nice if it worked on my Windows dev box as well as the *nix production box.

<?php
$utcdate = new DateTime('2014-01-01 13:15:00', new DateTimeZone('UTC'));
echo $utcdate->format('l \t\h\e jS \o\f F Y \a\t g:ia') . "<br>";
function dumpDates($date, $locale, $tz){
    $date->setTimeZone(new DateTimeZone($tz));
    $fmt = new IntlDateFormatter( $locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL,
         $tz, IntlDateFormatter::GREGORIAN  );
    echo $fmt->format($date) . "<br>";
    // doesn't work under windows?
    setLocale(LC_TIME, $locale);
    echo strftime('%A, %#d %B %Y %I:%M:%S %p', $date->getTimeStamp()) . "<br>";

}
dumpDates($utcdate, 'en_GB', 'Europe/London');
dumpDates($utcdate, 'de_DE', 'Europe/Berlin');
dumpDates($utcdate, 'fr_FR', 'Europe/Paris');
?>

Source: (StackOverflow)

How to install the Intl extension for Twig

The Intl extension is an extension for Twig that adds the localizeddate, localizednumber and localizedcurrency filters. How can I install and set up the extension so that I can use those filters in my Twig templates?


Source: (StackOverflow)

PHP Spoofchecker class

I'm reading through the PHP manual and came across the Spoofchecker class in the intl extension documentation pages. The methods in the class, their parameters, as well as the class itself are all fairly undocumented as of right now so I'm wondering what the purpose of it is.


Source: (StackOverflow)