php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50297 MessageFormatter::formatMessage don't support string with accent in it
Submitted: 2009-11-25 20:37 UTC Modified: 2009-11-29 13:07 UTC
From: pby_42-web at yahoo dot fr Assigned:
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.3.1 OS: Windows Vista 64
Private report: No CVE-ID: None
 [2009-11-25 20:37 UTC] pby_42-web at yahoo dot fr
Description:
------------
Using accent character in the pattern of MessageFormatter::formatMessage return an empty string.


Reproduce code:
---------------
echo (MessageFormatter::formatMessage("fr_FR", "with accent ? ?", array()));

Expected result:
----------------
to display: with accent ? ?

Actual result:
--------------
display nothing

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-26 10:08 UTC] jani@php.net
Try this:

  http://www.php.net/manual/en/messageformatter.geterrormessage.php

You might have something like wrong locale there or something..
 [2009-11-27 15:08 UTC] pby_fr at yahoo dot fr
formatMessage being a static method, it is not possible to use getErrorMessage!

I tested with a full object code:

$fmt = new MessageFormatter("fr_FR", "with accent ? ?");

$fmt isn't an object, but FALSE


Whit
$fmt = new MessageFormatter("fr_FR", "with accent a e");
$fmt is an object, and everything works fine.

Anyway, I must switch back to PHP 5.2, therefore I will recode a very simple formatter instead of use this class.
 [2009-11-27 17:47 UTC] jani@php.net
Well there's your problem. The method isn't static..
 [2009-11-29 13:07 UTC] pby_42-web at yahoo dot fr
No, formatMessage is a static function.

From the doc: 
static  string  formatMessage  ( string $locale  , string $pattern  , array $args  )
 [2010-09-05 00:03 UTC] clicky at erebot dot net
@pby_42-web at yahoo dot fr: I guess your string is encoded in ISO-8859-15.
AFAICT, ICU only accepts strings encoded in UTF-8. Converting your string in UTF-8 and using hexadecimal escape sequences, I got the following result:

$ php -a
Interactive shell

php > echo MessageFormatter::formatMessage("fr_FR", "with accent \xC3\xA9 \xC3\xA0", array());
with accent é à
php >

So, MessageFormatter DOES accept accentuated letters, you just have to be careful about their encoding. Maybe the documentation should be updated to state this more clearly.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 08 21:01:26 2020 UTC